前端js页面对后端返回的对象集合排序
function compare(property){ return function(a,b){ var value1 = a[property]; var value2 = b[property]; return value2 - value1 ; } } console.log(suggestions.sort(compare('price'))); //suggestions是集合名称,price是要比较的参数名
function compare(property){ return function(a,b){ var value1 = a[property]; var value2 = b[property]; return value2 - value1 ; } } console.log(suggestions.sort(compare('price'))); //suggestions是集合名称,price是要比较的参数名
相关推荐