Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.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 应用筛选器时数据源突然丢失_Javascript_Angular_Kendo Ui Angular2 - Fatal编程技术网

Javascript 应用筛选器时数据源突然丢失

Javascript 应用筛选器时数据源突然丢失,javascript,angular,kendo-ui-angular2,Javascript,Angular,Kendo Ui Angular2,我按照命令对下拉列表应用过滤器 下拉列表 <kendo-dropdownlist [data]="data" [(ngModel)]="selectedItem" [filterable]="true" [textField]="'text'" [valueField]="'value'" (filterChange)="handleFilter($event)" > <

我按照命令对下拉列表应用过滤器

下拉列表

 <kendo-dropdownlist
        [data]="data"
        [(ngModel)]="selectedItem"
        [filterable]="true"
        [textField]="'text'"
        [valueField]="'value'"
        (filterChange)="handleFilter($event)"
    >
 </kendo-dropdownlist>

数据来自后端服务

export class AppComponent implements OnInit {
public source: Array<myClass> = [];
public data: Array<myClass> = [];
public selectedItem: myClass;
constructor() {
    this.data = this.source.slice();
}

ngOninit() {
    this.getDataFromService();
}

public getDataFromService = () => {
    //  get data from backend
    this.service['myService'].get().subscribe(response => {
         this.source = response;
         thid.data = response;
    };
}

public handleFilter(value: any): void {
    console.log(this.source);
    this.data = this.source.filter((s) => s.text.toLowerCase().indexOf(value.toLowerCase()) !== -1);
 }
}
导出类AppComponent实现OnInit{
公共源:数组=[];
公共数据:数组=[];
publicselecteditem:myClass;
构造函数(){
this.data=this.source.slice();
}
恩戈尼尼特(){
这是.getDataFromService();
}
公共getDataFromService=()=>{
//从后端获取数据
this.service['myService'].get().subscribe(响应=>{
这个源=响应;
thid.data=响应;
};
}
public handleFilter(值:任意):无效{
console.log(this.source);
this.data=this.source.filter((s)=>s.text.toLowerCase().indexOf(value.toLowerCase())!=-1);
}
}
过滤器工作正常。但是有时在输入几次之后,过滤器就不工作了。“不工作”意味着下拉列表总是显示整个列表。看起来数据根本没有绑定。有时我发现
this.source
是空的。我不知道为什么

可能是javascript对象引用问题、角度渲染问题或绑定延迟异步问题

更新:


准确地说,实际上我在屏幕上有两个下拉控件和一些选项卡。两个下拉列表并排放置。html格式几乎相同,不同的是数据源。一开始,文件管理器工作正常。如果我在drpdown 1中多次使用过滤器,然后移动到dropdown 2进行一些过滤和go返回下拉列表1,数据没有绑定。或者,如果我在下拉列表1中多次使用过滤器,然后单击选项卡并返回下拉列表1,则数据也没有绑定。我的意思是两个下拉列表都没有绑定。

可能是我使用不正确,或者可能是剑道ui的错误

我把
[(ngModel)]
双向绑定和过滤放在一起了。我研究了文档,没有这样的用法。使用过滤器时,应该是单向绑定而不是双向绑定。我检查了文档


他们只是在使用过滤器时从不把
ngModel
放在那里。但是我有两个下拉列表,如果我从其中一个中选择,另一个应该设置为默认值或null。所以我需要找到一种方法来实现它,而根本不使用
ngModel

这是:
thid.data=response;
文章中的一个输入错误,还是你的代码应用程序?很抱歉,这是一个输入错误。this.dataPut
this.getDataFromService();
放入构造函数和
this.data=this.source.slice();
ngOnInit()
(更改位置)@Vinaysharma中,我尝试了它,但做了同样的事情。我还更新了问题。