如何在一个自定义控件中处理来自不同模型的两组
How to process two sets from different models in one custom control
目标:
我想将两个模型(数据集)传递给带有预定义搜索字段的自定义控件,稍后我可以在其中执行过滤。
我是 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);
我在这里没有提供用于控制的 Renderer 函数,但它存在并且这是其中最重要的摘录:
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/'}"
目标:
我想将两个模型(数据集)传递给带有预定义搜索字段的自定义控件,稍后我可以在其中执行过滤。
我是 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);
我在这里没有提供用于控制的 Renderer 函数,但它存在并且这是其中最重要的摘录:
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/'}"