如何在一个自定义控件中处理来自不同模型的两组

时间:2019-07-08 16:43:07

标签: javascript sapui5

目标:

我想通过预定义的搜索字段将两个模型(数据集)传递给自定义控件,稍后可以在其中执行过滤。

我是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] -

我不知道这是怎么回事。

1 个答案:

答案 0 :(得分:1)

问题是您忘记在路径中提供单引号: foo="{path: 'db2>/RC_DISEASE_TERM/'}"

相关问题