分解 jQuery 数组
Explode jQuery Array
我在 jQuery 中展开数组时遇到问题。
我想分解数组并将它们与父部分一起插入到数据库中
感谢您的帮助
你可以在js中使用php explode等价函数
var str = "string to be exploded and seperated each item by space";
var res = str.split(" ");
不知道你为什么要自爆?这是一个简短的示例,说明如何使用对象访问数组。
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("----------------");
});
如果你想要部分的每个部分:
input.splice(',')
Outputs: {"id" : 1, "parent" : 0}
{"id" : 2, "parent": 0, "children": [{"id": 3, "parent": 2}]}
我在 jQuery 中展开数组时遇到问题。
我想分解数组并将它们与父部分一起插入到数据库中
感谢您的帮助
你可以在js中使用php explode等价函数
var str = "string to be exploded and seperated each item by space";
var res = str.split(" ");
不知道你为什么要自爆?这是一个简短的示例,说明如何使用对象访问数组。
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("----------------");
});
如果你想要部分的每个部分:
input.splice(',')
Outputs: {"id" : 1, "parent" : 0}
{"id" : 2, "parent": 0, "children": [{"id": 3, "parent": 2}]}