jQuery USES each to process json data
- 2020-06-01 08:14:29
- OfStack
eg: when the corresponding value of ID is true in the incoming ID, add one class named focus to the corresponding ID tag, such as:
var obj = { id01:'true', id02:'flase', id03:'true'};
$.each(obj,function(key,val){
if(val == 'true'){
$('#' + key).addClass('focus');
}
});
Results: one class tag is added to the id01 and id03 ID labels.
eg2:
The data of json are as follows:
[
{"Id": 10004, "PageName": "club"},
{"Id": 10040, "PageName": "qaz"},
{"Id": 10059, "PageName": "beauty"}
]
To manipulate this data with jquery, use $.each:
$.each(data, function(i, item) {
alert(item.PageName);
});
My own test is feasible.
That's all for this article, I hope you enjoy it.