我是SAPUI5的新手,我有一个必须在sap.m.input控件上显示建议的要求。我正在尝试通过“建议”事件来执行此操作,但是我没有得到任何建议,也没有错误。 据我所知,建议事件将在用户输入时显示建议。如果我的代码出错了,请告诉我要使其正常工作必须纠正的内容。
XML:
<Label id='idDocLbl' text="" />
<Input id = "iddocNo" width="450px"
placeholder = "Enter Doc No ..."
showSuggestion="true"
showValueHelp = "true"
valueHelpRequest = "handleDocValueHelp"
enabled="true" change = "handleDocChange"
valueState = "None"
suggest = "handleDocSuggest">
</Input>
控制器:
handleDocSuggest: function (oEvent) {
var that = this;
var inputId = oEvent.getSource().getId();
var displayModel = sap.ui.getCore().getModel("displayModel");
var oSource = displayModel.getProperty("/sourceView");
var systemId = displayModel.getProperty("/systemId");
var compCode = displayModel.getProperty("/compCode");
var type = displayModel.getProperty("/type");
var prdId = this.getView().byId("idPrdid").getValue();
var viewname = oSource + "HDView";
var viewDependent = '';
var docField = sap.ui.getCore().getModel("configModel").getProperty("/docField");
sap.ui.getCore().getModel("displayModel").setProperty("/docField", docField);
var docid = this.getView().byId("iddocNo");
docid.setModel(displayModel);
oEvent.oSource.bindAggregation("suggestionItems", "/" + oSource, new sap.ui.core.ListItem({
text: "{" + docField + "}",
growing: true,
key: "{" + docField + "}"
}));
that._handleSuggest(oEvent, docField, viewDependent);
},
_handleSuggest: function (osuggest, viewkey, viewDependent) {
var lValue = osuggest.getParameter("suggestValue").toUpperCase();
var displayModel = sap.ui.getCore().getModel("displayModel");
var oSource = displayModel.getProperty("/sourceView");
var systemId = displayModel.getProperty("/systemId");
var compCode = displayModel.getProperty("/compCode");
var type = displayModel.getProperty("/type");
var prdId = this.getView().byId("idPrdid").getValue();
var filterArray = [];
filterArray.push(new sap.ui.model.Filter(viewkey, sap.ui.model.FilterOperator.Contains, lValue));
filterArray.push(new sap.ui.model.Filter("SYSTEM_ID", "EQ", systemId));
filterArray.push(new sap.ui.model.Filter("COMPANY_CD", "EQ", compCode));
filterArray.push(new sap.ui.model.Filter("DATA_CRCTN_TYP_CD", "EQ", type));
filterArray.push(new sap.ui.model.Filter("NGTL_WORKFLOW_STATUS", "NE", "Y"));
if (viewDependent.length > 0) {
var inputdepend_value;
inputdepend_value = this.getView().byId("idSystemId").getValue();
var oDepFilter = new sap.ui.model.Filter(viewDependent, sap.ui.model.FilterOperator.EQ, inputdepend_value);
var oDepFinal = [];
oDepFinal.push(oDepFilter);
oDepFinal.push(oFilter);
osuggest.getSource().getBinding("suggestionItems").filter(oDepFinal);
} else {
osuggest.getSource().getBinding("suggestionItems").filter([filterArray]);
}
},
答案 0 :(得分:0)
如果我正确理解了您的问题,那么您将无法显示建议项。您似乎已经在模型中包含了项目,因此可以将聚合直接设置为xml元素。
<Input id = "iddocNo" width="450px"
placeholder = "Enter Doc No ..."
showSuggestion="true"
showValueHelp = "true"
valueHelpRequest = "handleDocValueHelp"
enabled="true" change = "handleDocChange"
valueState = "None"
suggest = "handleDocSuggest"
suggestionItems="{displayModel>/sourceView}">
<suggestionItems>
<core:Item key="{key}" text="{Name}" />
</suggestionItems>
</Input>
这样,只要您在设置的模型路径中包含Imes,就应该弹出列表。
中的键<suggestionItems>
<core:Item key="{key}" text="{Name}" />
</suggestionItems>
在事件中传递,您可以在其中使用fron。
希望我有帮助。