所以在我分别获得所有数据后,我如何组织我的数组:
var arr = [{_1489378560544_544 : [customer_group_id : 0 , permission_id : 'permission_id'] }]
这是我的javascript get data函数:
$('#category_permission > tbody > tr').each(function() {
var id = $(this).attr("id");
var customer_group_id = $(this).children('td:first').children('select:first').val();
var permission_id = $(this).children('td:nth-child(2)').children('select:first').val();
});
感谢您的帮助!
答案 0 :(得分:0)
我认为数组不是键和值。对象只有键和值。所以像这样使用
var arr=[];
var n =[];
$('#category_permission > tbody > tr').each(function() {
var id = $(this).attr("id");
var customer_group_id = $(this).children('td:first').children('select:first').val();
var permission_id = $(this).children('td:nth-child(2)').children('select:first').val();
var inside = {
customer_group_id : customer_group_id,
permission_id: permission_id,
}
n.push(inside)
var k ={
_1489378560544_544:n,
}
arr.push(k)
});
console.log(arr)
var arr = [{
_1489378560544_544: [{customer_group_id: 0, permission_id: 'permission_id'}]
}]
console.log(arr)

它给出的结果看起来像这样