这是我目前的json回复。
[{"id":1,"name":"Yangon","$$hashKey":"object:170"}]
但我想在json上面添加新节点,如下所示,
[{"id":1,"name":"Yangon","$$hashKey":"object:170", "township_id": 1, "township_name": "Ahlone"}]
请帮我怎么做。提前谢谢。
答案 0 :(得分:1)
angular.extend
是另一种方法。
var arr = [{ "id": 1, "name": "Yangon", "$$hashKey": "object:170" }];
arr[0] = angular.extend(arr[0], {
"township_id": 1,
"township_name": "Ahlone"
});
答案 1 :(得分:1)
var arrayofobjects=[{"id":1,"name":"Yangon","$$hashKey":"object:170"}]
arrayofbojects[0].township_id: 1;
arrayofbojects[0].township_name: "Ahlone";
console.log(arrayobjectg[0])
试试这是经过测试的代码。
答案 2 :(得分:0)
您需要将响应存储到变量中(可能已经存在),只需添加您想要的任何键/值:
示例强>
var arr = [{ "id": 1, "name": "Yangon", "$$hashKey": "object:170" }];
arr[0]['township_id'] = 1;
arr[0]['township_name'] = 'Ahlone';
<强>结果强>
[{"id":1,"name":"Yangon","$$hashKey":"object:170","township_id":1,"township_name":"Ahlone"}]