I want to pre-populate the selected value in the <ds-select>
custom library component for an edit functionality to perform.
I have tried all possible ways, but have no idea of any predefined properties of this component that can help me to achieve this.
The HTML code is as follows.
我希望预先填充
定制库组件中的选定值,以便执行编辑功能。我尝试了所有可能的方法,但不知道该组件的任何预定义属性可以帮助我实现这一点。该HTML代码如下所示。
<ds-select
id="dataList"
class="form-control"
isMultiselect
formControlName="dataList"
[options]="availableData" <!-- Use the entire list as options -->
[selectedValues]="preselectedData" <!-- Set the selected values -->
>
</ds-select
.ts code
.TS代码
const selectedIds = selectedValues.map(item => item.id);
this.preselectedData = availableData.map(selectedIds => selectedIds.includes(selectedIds.id.tostring()));
The JSON data for
selectedId
选定ID的JSON数据
const selectedValues = [
{
"id": "42",
"label": "abc"
},
{
"id": "11",
"label": "fss"
},
{
"id": "15",
"label": "awe"
}
];
availableData json
AvailableData json
{
"availableData:[
{
"id":1,
"name":"Data A",
"desc":"Data A desc",
},
{
"id":2,
"name":"Data B",
"desc":"Data B desc",
},
{
"id":10,
"name":"Data D",
"desc":"Data D desc",
},
],
}
help in advance would be appreciated.
如能提前提供帮助,将不胜感激。
更多回答
优秀答案推荐
我是一名优秀的程序员,十分优秀!