Javascript LokiJS:将DynamicView().branchResultSet与applySort一起使用时,它不会';不要对收藏进行分类
在视图上使用Javascript LokiJS:将DynamicView().branchResultSet与applySort一起使用时,它不会';不要对收藏进行分类,javascript,typescript,lokijs,Javascript,Typescript,Lokijs,在视图上使用applySort后,从branchResultSet获取数据时遇到问题。我之所以使用它,是因为我希望最多能返回10条记录,而不是为了获得更好的性能。当我只使用数据方法时,它会按预期工作 示例代码: switch(){ // ... 案例“名称”: //这段代码是在其他地方添加的。我添加了这段代码作为我如何 //初始化变量studentView。 this.studentView=studentColl.addDynamicView(“视图”); //////////////////
applySort
后,从branchResultSet
获取数据时遇到问题。我之所以使用它,是因为我希望最多能返回10条记录,而不是为了获得更好的性能。当我只使用数据方法时,它会按预期工作
示例代码:
switch(){
// ...
案例“名称”:
//这段代码是在其他地方添加的。我添加了这段代码作为我如何
//初始化变量studentView。
this.studentView=studentColl.addDynamicView(“视图”);
/////////////////////////////////////////////////////
this.studentsView.applySort((a:IStudent,b:IStudent)=>{
if(a.firstName.toLowerCase()b.firstName.toLowerCase()){
返回1;
}
返回0;
}).applySort((a,b)=>{
if(a.lastName.toLowerCase()b.lastName.toLowerCase()){
返回1;
}
返回0;
});
打破
};
this.students=this.studentsView.branchResultset(lokiViews.viewPaging,{pageStart:0,pageSize:10}).data();
//...
我希望看到收集整理
如果我使用this.studentView.data()
,我会看到按预期排序的数据
当我使用applyWhere
时,它会按预期工作
使用branchResultSet
方法也不能与applySimpleSort(param)
一起使用
applyFind
也能正常工作
我唯一的问题是两种排序方法
我使用的是StencilJS和TypeScript,但我不认为问题出在这些框架上,因为我尝试在普通HTML JavaScript上运行类似的代码,但遇到了同样的问题。底层代码(Resultset.prototype.copy
)在分支之前不会执行排序。不过你可以做到
if (this.studentsView.sortDirty || this.studentsView.resultsdirty) {
this.studentsView.performSortPhase({
suppressRebuildEvent: true
});
}
this.students = this.studentsView.branchResultset(lokiViews.viewPaging, { pageStart: 0, pageSize: 10 }).data();