我是AngularJS的新手,现在我正试图在嵌套数组中插入一个新对象,我不知道它是如何完成的。这里我有/ sites / 100820(< - site id)的例子。我正在尝试在文本和值下面的状态中添加一个名为icon的新对象。如果你们知道应该怎么做,那么如果你和我分享你的知识,我将不胜感激!
{
"siteId": 100820,
"siteName": "Pumppaamo 01",
"measuringPoints": [{
"id": 102395,
"name": "Pumppu 2",
"measuringSubjects": [{
"id": 110313,
"name": "Käyntivirta",
"latestResult": 6.2700000000000005,
"latestDigitalResultText": null,
"digital": 0,
"latestReceived": "2008-11-10T04:00:22Z",
"unit": "A",
"latestResultAndUnit": "6.3 A",
"numberOfDecimals": 1,
"minValue": 0,
"maxValue": 30,
"alarmLevels": [{
"id": 103765,
"onLevel": 3,
"onEventTypeId": 3,
"offLevel": 3.187,
"offEventTypeId": 7,
"direction": "l",
"onLevelEventText": "Alivirtahälytys",
"offLevelEventText": "Alivirtahälytys poistunut",
"offDelay": 60,
"onDelay": 60,
"onEventTypeText": "Limit 1 ON",
"offEventTypeText": "Limit 1 OFF"
}, {
"id": 103766,
"onLevel": 10,
"onEventTypeId": 4,
"offLevel": 9,
"offEventTypeId": 8,
"direction": "u",
"onLevelEventText": "Ylivirtahälytys",
"offLevelEventText": "Ylivirtahälytys poistunut",
"offDelay": 60,
"onDelay": 60,
"onEventTypeText": "Limit 2 ON",
"offEventTypeText": "Limit 2 OFF"
}],
"status": {
"value": "OK",
"text": "Ok",
!RIGHT HERE!
}
},
答案 0 :(得分:2)
我会假设你是从前端的javascript尝试这个:
var obj = //this var is your object above;
obj.measuringPoints[0].measuringSubjects[0].status.icon = {/*your new object*/};
measuringPoints[0]
是一个数组0是所需的索引,您的样本对象只有一个值measuringSubjects[0]
包含您对象的第二级数组status
是对象的理想属性