自从过去这么多天以来,我一直在挠头寻找解决问题的方法,但是找不到它。以下是与dx标签框相关的问题的描述。 https://js.devexpress.com/Documentation/ApiReference/UI_Widgets/dxTagBox/
问题描述:我需要向dxtagbox添加尚不属于dxtagbox列表成员的自定义值。以下是我的html和ts代码以实现此功能。到目前为止,我已经尝试了多种方法,但没有成功。
common.component.html
<div class="row">
<div class="form-group col-md-12 mt-2">
<label>Region</label>
<dx-tag-box id="region-lookup" [dataSource]="regionListLookup" class="time-box" [showClearButton]="true"
style="height: auto !important;" [acceptCustomValue]="true"
[applyValueMode]="'useButtons'" (onKeyUp)="onEmptyingList($event)" (onValueChanged)="onClearingList($event)" [showSelectionControls]=true
[searchEnabled]="true" [value]="regions"
displayExpr="Value" valueExpr="Key">
</dx-tag-box>
</div>
common.component.ts
regions = [];
populateRegionslookup() {
this.regionListLookup = {
paginate: true,
store: new CustomStore({
key: 'Key',
load: async (loadOptions) => {
console.log('this: ', this);
console.log('loadOptions: ', loadOptions);
const paginatedData = { Text: loadOptions.searchValue, PageNo: loadOptions.skip, PageSize: loadOptions.take};
const result = await this.reportsService.getRegionsMetaData(paginatedData)
.toPromise();
console.log('this.reportsService.getRegionsMetaData("{' + loadOptions.searchValue + ' })', result);
result.map((resultItem) => {
resultItem.Value = `${resultItem.Key} - ${resultItem.Value}`;
return resultItem;
});
return result;
},
byKey: (key) => {
console.log('from byKey: ', key);
//code to return from api by key
}
})
};
}
onEmptyingList(event) {
if (event.event.key == 'Backspace' || event.event.key == 'Delete') {
//For Tagbox
if(event.element.id == 'region-lookup') {
this.taggedRegions = event.value;
this.timeReportsSearchModel.Region = this.taggedRegions;
this.missingOfficeTagBoxComponent && this.missingOfficeTagBoxComponent.instance.getDataSource().reload();
}
}
}
onClearingList(event) {
//For Tag Box
if(event.element.id == 'region-lookup') {
this.taggedRegions = event.value;
this.timeReportsSearchModel.Region = this.taggedRegions;
this.missingOfficeTagBoxComponent && this.missingOfficeTagBoxComponent.instance.getDataSource().reload();
}
}
constructor(){
this.regions = ["customValue1","customValue2","customValue3","customValue4"]
this.populateRegionslookup();
}
在这里,我想将“区域”数组值强制添加到标签盒,尽管这些值不是来自用于填充标签盒项目的api。如devexpress文档中所示,我什至无法在ui的标签框中键入自定义值。
有什么办法可以做到这一点,还是我只是在浪费时间,我应该尝试其他方法吗?
请帮助我。谢谢
答案 0 :(得分:0)
我找到了解决方案。我将新值添加到“ load”方法返回的“ result”对象中。在加载更多数据时,我从结果数组中删除了已添加的成员,因此不再重复它们。
skuNames