Cannot read property 'name' of undefined at valuePrepareFunction
- 主要语言
- TypeScript
- 星标
- 1.6k
- 派生
- 867
- PR 合并指标
- 30 天内没有已合并 PR
描述
Hello..
I have an object that contains a code property that is stored in the database, but its name does not exist in the database, so I need to find the name through the search code at options list . I used the following method , the data in the table is displayed correctly, but when loaded the page ,a lot of the following error are displayed in the console:
```
ERROR TypeError: Cannot read property 'name' of undefined
at valuePrepareFunction (example.component.ts:716)
at Cell.push../node_modules/ng2-smart-table/lib/data-set/cell.js.Cell.getValue (cell.js:19)
at Object.eval [as updateRenderer] (ViewCellComponent.html:5)
at Object.debugUpdateRenderer [as updateRenderer] (core.js:11948)
at checkAndUpdateView (core.js:11320)
at callViewAction (core.js:11556)
at execEmbeddedViewsAction (core.js:11519)
at checkAndUpdateView (core.js:11316)
at callViewAction (core.js:11556)
at execComponentViewsAction (core.js:11498)
```
**My options:**
```
this.options = [
{ name: 'Mary',code:1 },
{ name: 'Shelley',code:2 },
{ name: 'Igor',code:3 }
];
```
**My setting :**
```
settings = {
columns: {
objectCode: {
title: 'name',
type: 'string',
valuePrepareFunction: (code) => (code) ? this.options
.filter(object => object.code == code)[0].name : ""
}
}
}
```
**The data format assigned to the source:**
```
data = {
objectCode:1,
id:10,
...
}
ngOnInit() {
this.source.load(this.data);
}
```
Please help me!
贡献指南
这个仓库没有索引到贡献指南
评估
这个 Issue 还没有评估数据。