SapUI5- ComboBox项与模板绑定,抛出异常

时间:2016-03-24 08:29:51

标签: data-binding combobox sapui5

尝试将项目绑定到sap.ui.ComboBoxhttps://sapui5.netweaver.ondemand.com/sdk/#docs/api/symbols/sap.ui.commons.ComboBox.html)组件时遇到问题。

目前,在ComboBox组件上绑定项目的过程如下:

var itemTemplate = new sap.ui.core.ListItem();      //  creating a ListItem object                  
itemTemplate .bindProperty("text", ".........");   //  bind for the "text" property a certain path from the model



var comboBox = new sap.ui.commons.ComboBox({});    // create the ComboBox
comboBox .bindItems("........",itemTemplate);     // bind the items from a certain path, and provide as a template for the list the previously created one

除了在控制台上记录以下异常这一事实外,一切都按预期工作: " 共享模板必须使用templateShareable标记:绑定信息中为true - "

虽然这似乎具有启发性,但我仍然无法在绑定过程中找到" templateShareable"属性设置为" true"。

有没有其他人遇到过这个问题?绑定组合框的项目时我做错了吗?

由于

1 个答案:

答案 0 :(得分:1)

将为聚合中的每个项目克隆模板Element。因此,在您的示例中,您将获得数据源中每个项目的itemTemplate ListItem的一个克隆。

共享模板是许多控件将使用的模板对象。例如,如果您将ComboBox用作表中的模板,则将为每行克隆ComboBox。如果您的itemTemplate被标记为templateShareable:true,则不会克隆模板 - 所有ComboBox克隆都将使用相同的itemTemplate对象作为其项目的模板。

您可以将templateShareable指定为绑定参数:

comboBox.bindItems({ 
  path: "/items", 
  template: itemTemplate, 
  templateShareable:true
  });  

如果您没有指定templateShareable,则会假定为,但会收到警告。

请参阅jsbin:如果您对templateShareable:true行发表评论,您将再次在控制台中收到警告。

相关问题