Say we have JSON like this:
- Code: Select all
{"models":[{"id":1,"type":"Type 0"},{"id":2,"type":"Type 1"}]}
Previously, if I set action:
- Code: Select all
delete [email protected]"models", 0
The result will be like this: (Note that the first element becomes null.)
- Code: Select all
{"models":[null,{"id":2,"type":"Type 1"}]}
So I change the runtime.js at line 405, from this:
- Code: Select all
function deleteIfValid(obj,prop) {
if ( obj !== undefined && obj !== null &&
(typeof obj === "object") && obj[prop] !== undefined){
delete obj[prop];
} else {
log("invalid path: [email protected]"+ path_.toString(),"warn");
}
}
Into this:
- Code: Select all
function deleteIfValid(obj,prop) {
if ( obj !== undefined && obj !== null && obj[prop] !== undefined ) {
if( Object.prototype.toString.call( obj ) === '[object Array]' ) { // If object is an element of an array
obj.splice(prop,1); // delete element at index prop
} else if( Object.prototype.toString.call( obj ) === '[object Object]' ) { // If object is an object
delete obj[prop];
}
} else {
log("invalid path: [email protected]"+ path_.toString(),"warn");
}
}