Use insertItem after bindAggregation in Sap.m.Select

南笙酒味 提交于 2019-12-25 16:36:59

问题


Is my first time posting here.

I have a sap.m.Select that shows the Years from oDataModel using "bindAggregation" method.

My idea is to create a extra Item in the Select with text: "All Values" and Key: "*", So I tried to use the "insertItem" after the "bindAggregation", but the item that I created didnt appear in the Select list of items, only the Years from oDataModel.

Here is the code:

var yearSelectBox = this.getView().byId("idYearSelectBox");
yearSelectBox.setModel(new sap.ui.model.odata.ODataModel("../../../ui/WebContent/Kpi/services/dates.xsodata", true));
yearSelectBox.bindAggregation("items", "/Years", new sap.ui.core.Item({
            key: "{YEAR}",
            text: "{YEAR}"
        }),0);
yearSelectBox.insertItem(new sap.ui.core.Item({
            key: "*",
            text: "All Values"
        }));

I tried to use the insertItem before the bindAggregation, to use itemIndex = -1, 0, 20, but nothing changed.


回答1:


Unfortunately what you're trying to achieve - while making sense to you - doesn't make sense in the context of binding. When you bind a data model to a control, the control then bases all of its rendering on that model. Additionally, any changes via. the control are pushed back to the model - this keeps the model and control in sync. Thus you cannot simply add another item to the aggregation once a binding is in place. The binding controls what items are added (updated and removed), not programmatic interference. You have two simply options (perhaps others too): read your model data into a JSON model, including your All Values dropdown entry, then bind the dropdown control to that JSON Model, or add the All Values entry to the underlying OData database table so it shows up in the dropdown.



来源:https://stackoverflow.com/questions/30812075/use-insertitem-after-bindaggregation-in-sap-m-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!