Two ways for jquery to traverse object arrays
data:
[
{
"templateId":5,"policyTemplateName":"fix",
"createTime":"2016-08-26 09:26:07"
}, an object
{
"templateId":6,"policyTemplateName":"Basic Template","createTime":"2016-08-26 01:46:28"
} Another object
]
returned to the background It is the object array in the above format. There are two situations for jquery traversal. One is to traverse the object and obtain it through the object.properties. The other is to traverse the object again to get the k(policyTemplateName) and k(policyTemplateName) of each object. value (basic template) value,
The use of the two cases is explained below
The first case:
function(data) {
Parameter i: represents the number of objects
Parameter obj: represents an object
$.each (data,function(i, obj) {
//Get the value of the corresponding field
console.log(obj.obj.templateId);
console.log(obj.obj.policyTemplateName);
});
}
th Two situations:
function(data) {
Parameter i: represents the object number
Parameter obj: represents an object
$.each(data, function(i, obj) {
//Traverse object obj again
Parameter k: represents the attribute name of the object
Parameter v: represents the attribute value of the object
$.each(obj,function(k,v){
if(k=="policyTemplateName"){
console.log(v);
}
});
});
}