Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2801

Re: How to extract the data from JSONModel by condition ?

$
0
0

Hi Wei,

 

 

First, you have to retrive the Array from your JSONModel using following method.

var oArray = this.getView().getModel("modelName").getProperty("/rootStringValue");

 

Then you have to loop through both array and JS object. In your case, the dataUser is already an Array.

 

var i, name, obj, targetIndex;

 

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

     obj = dataUser[i];

     for (name in obj) {

          if ( name == "user_name" && obj.name == "user_2")

             targetIndex = i;

     }

}

 

via this targetIndex, you can locate the right array element contains the information and you can retrieve what you want.

var targetObj = dataUser[targetIndex];

var id = targetIndex.user_id;


I think this id is namely what you I want. My code is not optimized, but  I think the logic is right. You can give it a try.


Regards,

La


Viewing all articles
Browse latest Browse all 2801

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>