0

I'm new with AngularJS and right now I'm trying to insert a new object in nested array and I'm not sure how it's done. Here I have example of /sites/100820 (<-- site id). I'm trying to add a new object called icon in status right under the text and value. If you guys know how it should be done then I would be appreciated if you share your knowledge with me!

{
"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!
        }
    },

1 Answer 1

2

I will asume you are trying this from javascript in the front-end:

var obj = //this var is your object above;

obj.measuringPoints[0].measuringSubjects[0].status.icon = {/*your new object*/};
  • measuringPoints[0] is an array 0 is the desired index, your sample object only has one value
  • measuringSubjects[0] the second level array that contains your object
  • status is the desired property of the object
Sign up to request clarification or add additional context in comments.

1 Comment

think you're gonna need measuringSubjects in there!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.