我在循环、对象方面遇到了一些麻烦
我有这样的json;
var jsonPermission = {"permissions": [
{"permissionId": 1, "permissionName": "Admin Permission", "roleDesc": "This is an Admin Permission"},
{"permissionId": 2, "permissionName": "Manager Permission", "roleDesc": "This is a Manager Permission"},
{"permissionId": 3, "permissionName": "User Permission", "roleDesc": "This is a user Permission"}
]
};
我必须制作这样的对象;
[
{ data: "Admin Permission", type: ["permission"] },
{ data: "Manager Permission", type: ["permission"] },
{ data: "User Permission", type: ["permission"] }
]
所以我使用了以下代码;
//For Permissions
var permissions_len = jsonPermission.permissions.length;
var arr_permissions = [];
var permission_type = ["permission"];
for(var i=0;i<permissions_len;i++){
var obj_permissions = {};
obj_permissions["data"] = jsonPermission.permissions[i].permissionName;
obj_permissions["type"] = permission_type;
arr_permissions.push(obj_permissions);
}
但相反,我是这样的:
[
{ data: "Admin Permission", type: [1] },
{ data: "Manager Permission", type: [1] },
{ data: "User Permission", type: [1] }
]
怎么表现?