cancel
Showing results for 
Search instead for 
Did you mean: 

How to update particular json key value in local JSON model

Former Member
0 Kudos

I have a local json model

like:

{

"CompliantCollection": [

{

"ComplaintId": "123",

"Name": "Software Installations",

"Description": "SAP NetWeaver AS ABAP 7.50 SP2 Developer Edition Installation on MAC O",

"TicketDate":"11/01/2017 12:50:50",

"CurrentOwner":"Admin",

"Address":"A-293,New Ashok Nagar,new Delhi",

"Status":"Pool"

}

]

}

Need to update Status to WIP for ComplaintID :123

How to do ?

Accepted Solutions (1)

Accepted Solutions (1)

antonette_oberholster
Active Contributor
0 Kudos

Hey Gaurav

Try something like this:

var collection = <mymodel>.getProperty("/CompliantCollection");

for (var i = 0; i < collection.length; i++) {

if (collection[i].ComplaintId== "123")

<mymodel>.setProperty("/CompliantCollection/" + i + "/Status", "WIP");

};

Hope this help

Antonette 🙂

Former Member
0 Kudos

My JsonArray may be consist of large no of records(upto 100).

for update one key , i need to iterate the whole array.

Any other approach.

Gaurav Mittal

junwu
Active Contributor
0 Kudos

100 is nothing......

Answers (1)

Answers (1)

Former Member
0 Kudos

Gaurav,

I am trying to understand your use case here. You might probably have complainCollection items listed as a list or table control in your view.

The change that you are talking about in the status will be happening from the view via an editable input control or edit button. This is one common use case. If this is your scenario too, you can get the binding element (on what item the edit event occurs) in your controller using event listeners and you can directly set the value there.

But, if you want to trigger and set the change only in controller - I mean without the change being triggered from view (Not a common scenario though) , you would have to search the array for the right object (Object with complaint ID=123) before setting STATUS=WIP. Which search algorithm to use is upto you.

If this doesn't help, Please share your view and controller code so we can try solving it better.

Thanks,

Murali L