2 种绑定 ngModel 更改的方式也反映在其分配的临时变量中(在页面加载时分配)
2 way binding ngModel changes is also reflecting in its assigned temp variable(assigned on page load)
我有一个 2 路绑定模型,我在页面加载时将其分配给一个临时变量。但是 temp 变量也接受了 NgModel 的变化。
this.questionService.getAll(this.id, this.bcID).subscribe(_result => {
this.questions = _result.data.filter(x => x.isDeleted === false);
this.tempQuestions = _result.data.filter(x => x.isDeleted === false);
});
使用 KEndo UI 网格
<kendo-grid [data]="gridView"
[height]="550"
[skip]="gridState.skip"
(edit)="editHandler($event)"">
this.gridView = process(this.questions, this.gridState);
基本上变量this.questions
和this.tempQuestions
都指向同一个对象。为确保更改不会反映回 this.tempQuestions
,请深度克隆 this.questions
对象。
这会有所帮助
this.questionService.getAll(this.id, this.bcID).subscribe(_result => {
this.questions = _result.data.filter(x => x.isDeleted === false);
this.tempQuestions = JSON.parse(JSON.stringify(this.questions));
});
我有一个 2 路绑定模型,我在页面加载时将其分配给一个临时变量。但是 temp 变量也接受了 NgModel 的变化。
this.questionService.getAll(this.id, this.bcID).subscribe(_result => {
this.questions = _result.data.filter(x => x.isDeleted === false);
this.tempQuestions = _result.data.filter(x => x.isDeleted === false);
});
使用 KEndo UI 网格
<kendo-grid [data]="gridView"
[height]="550"
[skip]="gridState.skip"
(edit)="editHandler($event)"">
this.gridView = process(this.questions, this.gridState);
基本上变量this.questions
和this.tempQuestions
都指向同一个对象。为确保更改不会反映回 this.tempQuestions
,请深度克隆 this.questions
对象。
这会有所帮助
this.questionService.getAll(this.id, this.bcID).subscribe(_result => {
this.questions = _result.data.filter(x => x.isDeleted === false);
this.tempQuestions = JSON.parse(JSON.stringify(this.questions));
});