封装一个排序函数用sort()
compare:function (property) {
return function (a, b) {
var value1 = a[property];
var value2 = b[property];
return value1 - value2;
}
},
调用
res.sort(that.compare(“id”));
请求到的数据例如以下
var test=[
{
price:15,
id:1,
description:‘这是第一个数据’
},{
price:30,
id:3,
description:‘这是第二个数据’
},{
price:5,
id:2,
description:‘这是第三个数据’
}
];