iRSF 빠 르 고 간단 하 며 사용 하기 쉬 운 구현 목록, 정렬, 필터 기능
4058 단어 정렬
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 = setting.src || {};
this.clonePropertyList = function()
{
var tmp_data = [];
for(var i in this.src[this.property])
{
tmp_data[i] = this.src[this.property][i];
}
return tmp_data;
};
this.clone = function()
{
var result = {};
var tmp_data = this.clonePropertyList();
return result[this.property] = tmp_data;
}
}
function iRSFFilter()
{
this.filters = {};
this.filtering = function(src_data)
{
var ret = [],i= src_data.length-1;
for(;i>=0;i--)
{
var flag = true;
for(var j in this.filters)
{
var fn_filter = this.filters[j];
if(typeof fn_filter == "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 = setting.src || {};
this.iSource.property = setting.property || "items";
};
this.records = function()
{
var $data = this.iSource.clonePropertyList();
$data = this.filter.filtering($data);
$data = this.sorter.sorting($data);
var result = {};
result[this.iSource.property] = $data;
if(this.draw !== undefined && this.draw !== null && typeof this.draw === "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;
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
엑셀 VBA에서 동적 계획법으로 DNA 서열의 정렬 만들기 Needleman-Wunsch 알고리즘 구현이 기사는 DNA 서열의 정렬을 반환하는 엑셀 함수에 대한 기사입니다. 그렇다면 다음과 같은 정렬을 반환하는 함수입니다. 두 개의 행렬을 준비합니다. 정렬하고 싶은 2개의 DNA 서열의 길이를 m과 n으로 하면, 세...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.