JSON 数字排序多字段排序介绍

时间:2013-09-18    点击:80   
复制代码 代码如下:

//排序数组
function SortBy(field, reverse, primer) {
reverse = (reverse) ? -1 : 1;
return function (a, b) {
a = a[field];
b = b[field];
if (typeof (primer) != 'undefined') {
a = primer(a);
b = primer(b);
}
if (a < b) return reverse * -1;
if (a > b) return reverse * 1;
return 0;
}
}
nodes.sort(SortBy('orderNum', false, parseInt));

把过个字段合并成单个 然后 排序字符串
复制代码 代码如下:

nodes.sort(function (a, b) { return a.sort.localeCompare(b.sort) });
script不刷新页面的联动前后代码
js 中的switch表达式使用示例
javascript实现促销倒计时+fixed固定在底部
jquery等宽输出文字插件使用介绍
使用indexOf等在JavaScript的数组中进行元素查找和替换
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved