答案 0 :(得分:0)
你可以在js中使用php explode等效函数
IWeird
答案 1 :(得分:0)
我不知道为什么你需要爆炸?以下是如何使用对象访问数组的简短示例。
var input = [{"id" : 1, "parent" : 0}, {"id" : 2, "parent": 0, "children": [{"id": 3, "parent": 2}]}];
input.forEach(function(object, index) {
console.log("Id: " + object.id);
window.document.write("<br>Id: " + object.id + "<br>");
console.log("Parent: " + object.parent);
window.document.write("Parent: " + object.parent + "<br>");
if(typeof object.children !== 'undefined') {
console.log("Has Children: true");
window.document.write("Has Children: true" + "<br>");
object.children.forEach(function(childObject, childIndex) {
console.log("Child-Id: " + childObject.id);
console.log("Child-Parent: " + childObject.parent);
window.document.write("Child-Id: " + childObject.id + "<br>");
window.document.write("Child-Parent: " + childObject.parent + "<br>");
});
}
else {
console.log("Has Children: false");
window.document.write("Has Children: false" + "<br>");
}
console.log("----------------");
window.document.write("----------------");
});
&#13;
如果你想要部分的每一部分:
input.splice(',')
Outputs: {"id" : 1, "parent" : 0}
{"id" : 2, "parent": 0, "children": [{"id": 3, "parent": 2}]}