javascript - 如何在一个自定义控件中处理来自不同模型的两组
问题描述
目标:
我想使用预定义的搜索字段将两个模型(数据集)传递给自定义控件,稍后我可以在其中执行过滤。
我是 OpenUi5 的新手,所以我可能在这里做错和愚蠢的事情。我从一个简化的任务开始,将数据从前端传递到我的自定义控件并遇到麻烦。
简化想法的背景:
创建一个带有聚合的自定义控件foo
,它的值将从视图中提供。还要创建另一个聚合元素 _searchField,它将使用视图提供的数据进行填充。每次用户在 _searchField 中输入时触发 onSuggestTerm。
自定义控制代码:
function (Control) {
var DropDownListInput = Control.extend('xx.control.DropDownListInput', {
metadata: {
defaultAggregation: 'foo',
aggregations: {
foo: { type: 'sap.m.SuggestionItem', multiple: true, singularName: 'suggestionItem' },
_searchField: { type: 'sap.m.SearchField', multiple: false, visibility: 'hidden' }
}
}
});
DropDownListInput.prototype.init = function () {
var that = this;
this.onSuggestTerm = function (event) {
var oSource = event.getSource();
var oBinding = that.getAggregation('foo');
oBinding.filter(new sap.ui.model.Filter({
filters: new sap.ui.model.Filter('DISEASE_TERM', sap.ui.model.FilterOperator.Contains, ' Other')
}));
oBinding.attachEventOnce('dataReceived', function () {
oSource.suggest();
});
};
this.setAggregation('_searchField', new sap.m.SearchField({
id: 'UNIQUEID1',
enableSuggestions: true,
suggestionItems: that.getAggregation('foo'),
suggest: that.onSuggestTerm
}));
};
return DropDownListInput;
}, /* bExport= */true);
我没有在这里提供用于控制的渲染器功能,但它存在,这是其中最重要的摘录:
oRM.write('<div');
oRM.writeControlData(oControl);
oRM.write('>');
oRM.renderControl(oControl.getAggregation('_searchField'));
oRM.write('</div>');
从 xml 前端将数据传递给该控件:
<xx:DropDownListInput
id="diseaseTermUNIQUE"
foo='{path: db2>/RC_DISEASE_TERM/}'>
<foo>
<SuggestionItem text="{db2>DISEASE_TERM}"
key="{db2>DISEASE_TERM}" />
</foo>
</xx:DropDownListInput>
代码无法运行并出现此错误Cannot route to target: [object Object] -
我不知道这里出了什么问题..
解决方案
问题是您忘记在路径中提供单引号:
foo="{path: 'db2>/RC_DISEASE_TERM/'}"
推荐阅读
- c# - 4.4 Bot Framework 中的 AzureBlobStorage 实现
- javascript - Mongoose - 后保存挂钩未触发
- android - atom文本编辑器适合写Java编程和android吗?
- mysql - MariaDB 安装失败,没有可用的软件包
- python - 将 django loader.render_to_string() 转换为用于 sendgrid 的烧瓶
- git - 卸载和安装 Homebrew 时出现 Git 错误
- go - 如何漂亮地打印 Golang 结构?
- c# - 无法运行 db2 查询?
- powerbi - 在复制行时用 DATE 值和计数值转置表
- google-apps-script - 为什么谷歌应用脚本触发器会发送重复的电子邮件?