jQuery:JSON 对象子项处理
jQuery: JSON object children handling
我正在尝试通过javascript函数进行<table>
。
我得到一个看起来像这样的 JSON 元素:
header
["Nom", "Région", "Activité", 10 more...]
0 "Nom"
1 "Région"
2 "Activité"
// other fields
body
Object { entity0=[13], entity1=[13], entity2=[13], more...}
entity0
["Org2", "Org2", "Org2", 10 more...]
0 "Org2"
1 "Org2"
2 "Org2"
//Other fields
entity1
["gfhu", "rtyud", "dgud", 10 more...]
//Other entities
我正在尝试像那样解码它(我解析 JSON 并将其提供给该函数):
function createTableEntity(tab, id){
table = '<table cellpadding="0" cellspacing="0" border="0" class="display" id="'+id+'">';
table = table + '<thead><tr>';
$(tab.header).children().each(function(){
table = table + '<td>' + this + '</td>';
});
table = table + '</tr></thead>';
table = table + '<tbody>';
$(tab.body).children().each(function(){
table = table + '<tr>';
$(this).children().each(function(){
table = table + '<td>' + $(this) + '</td>';
});
table = table + '</tr>';
});
table = table + '</tbody>';
table = table + '</table>';
//alert(table);
return table;
}
从我得到的结果来看,没有孩子($(tab.header).children().each(function(){});
)。
它从何而来?如何遍历从 JSON 解析的元素?
你不需要jquery来循环JSON解析的结果,因为它是一个Javascript对象。
如果你在tab.header中有一个数组,你可以简单地循环它
$.each(tab.header, function() {
或者更经典的是,没有jquery,使用
for (var i=0; i<tab.header.length; i++) {
相关文章:
- 处理对象数组并将它们以 4 个为一组进行分配
- 尝试在 JavaScript 中动态处理对象属性
- json.stringfy不处理对象方法
- 递归循环,直到我们'重新处理对象[JS]
- array.sort无法处理对象数组
- for循环未处理对象
- 如何在Angular中处理对象特性更改
- 如何在自执行匿名函数中处理对象
- 为什么我要声明handle["/"]在请求处理对象在HTTP服务器与node.js
- 如何处理对象属性内的事件函数
- 如何在预输入中处理对象
- 为什么在通过AJAX发送数据时,必须使用JSON.stringify()来处理对象?
- 如何处理对象收集中的数据
- 处理对象的ajax返回数组
- 使用unshift和pop序列处理对象数组
- 在JavaScript中处理对象和创建返回值的方法
- 通过四个异步调用收集数据到对象,并立即处理对象
- 如何处理对象字面量中的错误处理
- 在处理对象时需要帮助理解函数绑定
- Nodejs:如何处理对象之间的事件监听