fArray中文API V1.0.1★分享
使用场景
本插件主要用于:数据筛选、排序、循环等操作,让开发者操作数据更加便捷快速。下面跟我一起体验一下它的特点吧!
插件源码
插件下载:fArray1.0.1-min.rar
实例讲解
//数据
var data = [
{"name":"小樊","age":25,"birthday":"1192-05-13"},
{"name":"虎哥","age":28,"birthday":"1189-12-26"},
{"name":"大圣","age":26,"birthday":"1191-02-21"},
{"name":"安云","age":26,"birthday":"1191-02-21"}
];
//初始化数据,初始化的数据必须是数组哟
var fArr = new fArray(data);
//获取当前数据
fArr.arr;
//获取属性
fArr.get('name'); //返回:["小樊", "虎哥", "大圣", "安云"]
fArr.get('name').join(','); //返回:"小樊,虎哥,大圣,安云"
//筛选数据
fArr.get('birthday==1191-02-21');
返回:
[
{"name":"大圣","age":26,"birthday":"1191-02-21"},
{"name":"安云","age":26,"birthday":"1191-02-21"}
]
//循环数组
fArr.each(function(thisArr,index){
console.log(thisArr); //打印每一个数组
console.log(index); //打印当前的索引
if (thisArr.birthday=='1191-02-21') {
console.log(thisArr); //打印出birthday=='1191-02-21',的2个对象
};
});
//数据排序
fArr.sort('birthday'); //默认按birthday升序排列
返回:
[
{"name":"小樊","age":25,"birthday":"1192-05-13"},
{"name":"大圣","age":26,"birthday":"1191-02-21"},
{"name":"安云","age":26,"birthday":"1191-02-21"},
{"name":"虎哥","age":28,"birthday":"1189-12-26"}
]
fArr.sort('birthday','down'); //按birthday降序排列
返回:
[
{"name":"虎哥","age":28,"birthday":"1189-12-26"},
{"name":"大圣","age":26,"birthday":"1191-02-21"},
{"name":"安云","age":26,"birthday":"1191-02-21"},
{"name":"小樊","age":25,"birthday":"1192-05-13"}
]
fArr.sort(function(a,b){
return a.age - b.age; //自定义排列
});
敬请期待...