javascript - 使用`forEach`向表中添加多行而不影响浏览器性能
问题描述
我通过从模型(子组件)添加名称来在父组件中生成动态表列和行。
父组件 HTML。
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th>Words</th>
<th *ngFor="let wordList of wordList">{{wordList.word}}
</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let keys of workModel">
<td>{{keys.key}}</td>
<td *ngFor="let translation of keys.translation">
<input type="text" [name]="keys.key" [(ngModel)]="translation.value">
</td>
</tr>
</tbody>
</table>
在服务中,我正在调用这个函数。
addWord( newWordName : string ) {
const addWord = {
language: newWordName,
value: ''
};
this._workModel.forEach( ( data : EditorInstance ) => {
data.translation.push( { ...addWord } );
} );
}
每当我添加一个新词时,浏览器都会进入非响应模式,即它会挂起浏览器。这里this._workModel
可能还包含一些值。
下面的附加内容。所以我尝试changeDetection
在它的父组件中实现。
addNewWord( newWord : string ) {
this.cdr.detach();
setInterval(() => {
this.cdr.detectChanges();
this._translatorEditorService.addLanguage( newLanguage )
.then( () => {
} ).catch( () => {
} );
}, 5000);
}
但还是一样。是否有任何其他实现方式来实现在forLoop
.
解决方案
推荐阅读
- javascript - 我有一个下拉菜单和两个单选按钮。已选中 Onload 单选按钮“A”。在将下拉值更新为 123 单选按钮 B 时需要检查
- assembly - 手臂组件中的机器代码查找(分支)
- intellij-idea - IntelliJ IDEA:如何在结构替换期间创建新的类字段
- tensorflow - TensorFlow 找不到 GPU
- python - Django URL 看不到链接及其 POST 请求
- reactjs - react-native 错误:捆绑失败:SyntaxError: React native projects\appOne\node_modules\@react-navigation\routers\src\index.tsx
- javascript - Mousemove 位置在实时站点上不平滑
- python - 如何将数据帧转换为 Apriori 算法的数据帧
- c++ - const 还是不 const?
- ios - iOS 上的 Firebase 动态链接不起作用。动态链接网址始终为零