输入框中的SAP UI5实时搜索不起作用

问题描述 投票:0回答:1

我遵循了这个示例,https://sapui5.hana.ondemand.com/sdk/#/entity/sap.m.Input/sample/sap.m.sample.InputAssisted开发了与此类似的功能,但是在编写时,我的输入框没有填充,也没有搜索。当我按帮助对话框按钮时,将列出所有值,但无法在其中搜索。

代码如下:View.xml:

<Input
    id="productInput"
    type="Text"
    placeholder="Enter Product ..."
    showSuggestion="true"
    valueHelpRequest="handleValueHelp"
    showValueHelp="true"
    suggestionItems="{AgrName}" >
    <suggestionItems>
        <core:Item text="{AgrName}" />
    </suggestionItems>
</Input>

在Controller初始化函数中将Odata转换为JSON

var oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/ZGETJOBROLES_SRV/", true);

oModel.setSizeLimit(100000);
this.getView().setModel(oModel);

var jsonModel = "";
oModel.read("/DefineRolesTableSet", null, null, false, function(oData, oResponse) {
    jsonModel = oData;

});

var jData = new sap.ui.model.json.JSONModel(jsonModel);

this.getView().setModel(jData, "dataModel");
console.log(jData);     

handleValueHelp函数

handleValueHelp: function(oEvent) {

    var sInputValue = oEvent.getSource().getValue();

    this.inputId = oEvent.getSource().getId();
    //sInputValue.getModel().getJSON(); 
    // create value help dialog
    if (!this._valueHelpDialog) {
        this._valueHelpDialog = sap.ui.xmlfragment(
            "JobRoleSearch.View.Dialog",
            this
        );
        this.getView().addDependent(this._valueHelpDialog);
    }

    // create a filter for the binding

    this._valueHelpDialog.getBinding("items").filter([new Filter(
        "AgrName",
        sap.ui.model.FilterOperator.Contains, sInputValue
    )]);

    // open value help dialog filtered by the input value
    this._valueHelpDialog.open(sInputValue);
}

Results of console.log

我的意图是在客户端而不是服务器端进行搜索,这就是为什么我将oData转换为JSON的原因。如果有任何错误,请告诉我。

问候

odata sapui5
1个回答
0
投票

如果您不熟悉SAPUI5,则有一些免费的OpenSAP课程,您可以在其中观看一些教程和实用的enter link description here,我想您的模型有问题,请尝试suggestionItems="{/AgrName}"。这是绑定本地json模型的示例:

  1. Manifest.json

    "mainService": {
            "uri": "",
            "type": "OData",
            "settings": {
                "odataVersion": "2.0",
                "localUri": "localService/metadata.xml"
            }
        },
        "resource": {
            "type": "JSON",
            "uri": "model/Resources.json"
        },
        "location": {
            "type": "JSON",
            "uri": "model/Locations.json"
        }
    
  2. [Json文件:

    {“资源”:[{“ ID”:1,“名称”:“ TitMLocations”,“数字”:0,“ ValueColor”:“良好”,“ Icon”:“ sap-icon:// building”,“ LocationType”:“”},{“ ID”:2“名称”:“ TitMCar”,“数字”:0,“ ValueColor”:“良好”,“ Icon”:“ sap-icon:// car-rental”},{“ ID”:3,“名称”:“ TitMEquipment”,“数字”:0,“ ValueColor”:“良好”,“ Icon”:“ sap-icon:// add-equipment”}]}

  3. XML绑定

    items =“ {资源> /资源}

© www.soinside.com 2019 - 2024. All rights reserved.