Is this a right way to code a contents of view in controller, for a comboBox

Viewed 53
new sap.m.ComboBox({
id: "samplecombo",
items: "{path:'sample>/'}",
content: [ new sap.ui.core.Item({
text: "sample>Items", // string
key: "sample>Items" // string
}) 
]                                                   
})

this code is used to call a combobox within the controller, is this code right as am getting an error stating

"Missing template or factory function for aggregation items of Element sap.m.ComboBox".

1 Answers

As the error message suggests you have to provide a template or factory function.

items and content are two different aggregations (and I think ComboBox doesn't even have the content aggregation). If you want to render items, you have to add all the info to the items attribute. Here in the docs they have explained this in more detail. And here is the API where the parameters for a proper binding info object are documented.

As you can see you can provide the attribute template to your binding info.

new sap.m.ComboBox({
    id: "samplecombo",
    items: {
        path:'sample>/',
        template: new sap.ui.core.Item({
            text: "sample>Items",
            key: "sample>Items"
        }) 
    }                                               
})
Related