[英]How to push custom array object in ng2 smart table
https://github.com/akveo/ng2-smart-table在設置對象中,我們定義結構以顯示名稱,標題等字段。我想直接將對象分配給列。 對象包含字段
only.settings = {
editable: false,
mode: 'inline',
add: {
confirmCreate: true
},
edit: {
confirmSave: true,
},
actions: {
delete: false
},
columns: {
food: {
title: 'Food',
filter: false,
},
quantity: {
title: 'Quantity',
filter: false,
},
unit: {
title: 'Unit',
filter: false,
editor: {
type: 'list',
config: {
list: [
{ value: 'gm', title: 'gm' },
{ value: 'slice', title: 'slice' },
{ value: 'cup', title: 'cup' },
{ value: 'glass', title: 'glass' },
{ value: 'pcs', title: 'pcs' },
{ value: 'ml', title: 'ml' },
{ value: 'bowl', title: 'bowl' },
{ value: 'tbspn', title: 'tbspn' }
]
}
}
},
我必須創造
array =>units[]= { value: 'bowl', title: 'bowl' },{ value: 'tbspn', title: 'tbspn' }
要分配=>
清單:this.units
但它不起作用。 以防我通過Web服務調用獲取數組。
碼:
const options = [];
for (const unit of units) {
options.push({ value: unit.val, title: unit.name });
}
this.settings.columns.unit.editor.config.list = options;
this.settings = Object.assign({}, this.settings);
從Web服務接收數組后,請映射元素以轉換為智能表中使用的結構。
對於地圖參考: Array.map
就像這樣:
config.list = unitsFromWebservice.map(function(unit) {
return { value: unit, title: unit };
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.