首页 > 代码库 > iRSF快速简单易用的实现列表、排序、过滤功能

iRSF快速简单易用的实现列表、排序、过滤功能

 IRSF 是由javascript编写,iRSF快速简单易用的实现列表、排序、过滤功能(该三种操作以下简称为 RSF )。

iRSF由三个类组成。

iRSFSource 数据源iRSFFilter 过滤器iRSFSorter 排序器  

iRSF 使用:

iRsf = new iRSF();iRsf.draw = function(data){//展现列表,data的结构为{property:[{data1},{data2}]},* property 可以自定义,由iRSFSource 指定。};//指定数据源iRsf.setSource({src:{items:[{id:1121,name:"dfsa"},{id:1122,name:"dfsa"}]},property:"items"});//添加过滤器iRsf.addFilter("id",function(row){return row.id==1121;});//设置排序iRsf.setSort(function(a,b){return a.id-b.id;});//执行,并重画列表 会调用iRsf.draw方法iRsf.records();

iRsf 源码:

/** * 展现列表、排序、过滤(该三种操作以下简称为 RSF ) * iRSF快速简单易用的实现列表,排序,过滤等功能 * User: oshine * Date: 13-7-30 * Time: 上午11:31 */function iRSFSource(setting){    this.property = setting.property || "items";    this.src = http://www.mamicode.com/setting.src || {};"function")                {                    flag = flag && fn_filter(src_data[i]);                }                if(!flag)                {                    break;                }            }            if(flag)            {                ret.push(src_data[i]);            }        }        return ret;    };    this.clearFilters = function()    {        for(var j in this.filters)        {            this.filters[j] = null;            delete this.filters[j];        }    }}function iRSFSorter(){    this.sort = null;    this.sorting = function(src_data)    {        if(this.sort === undefined || this.sort == null || typeof this.sort !== "function")        {            return src_data;        }        src_data.sort(this.sort);        return src_data;    }}function iRSF(){    this.iSource = new iRSFSource({src:{},property:"items"});    this.sorter = new iRSFSorter();    this.filter = new iRSFFilter();    this.draw = null;    this.setSource= function(setting)    {        this.iSource.src = http://www.mamicode.com/setting.src || {};"items";    };    this.records = function()    {        var $data = http://www.mamicode.com/this.iSource.clonePropertyList();"function")        {            this.draw(result);        }        return result;    };    this.addFilter = function(name,filter)    {        this.filter.filters[name] = filter;    };    this.removeFilter = function(name)    {        if(this.filter.filters[name] == undefined)        {            return true;        }        this.filter.filters[name] = null;        delete this.filter.filters[name];        return true;    };    this.setSort = function(sort)    {        this.sorter.sort = sort;    };    this.clearSort = function()    {        this.sorter.sort = null;    }}