Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript LokiJS:将DynamicView().branchResultSet与applySort一起使用时,它不会';不要对收藏进行分类_Javascript_Typescript_Lokijs - Fatal编程技术网

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();