最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SAPUI5 Create ComboBox dynamically in controller - Stack Overflow

programmeradmin10浏览0评论

Currently I am developing of SAPUI5 application, in my page. I have to create ComboBox dynamically based on data from microservices.

i follow sample code from following url. view-source:.html

However, it return me empty in my bobox

The following is my sample code.

$.ajax({
                    url: "json/customers.json", 
                    dataType: 'json',
                    success: function(response){
                        var data= response; 
                        console.log(data);
                        var customerModel = new JSONModel(data);
                        console.log(customerModel);
                        oController.getView().setModel(customerModel, "customerJSON");
                        var ExtensionForm = oController.getView().byId("Extension_Form");

                                ExtensionForm.addContent(new sap.m.ComboBox(oController.getView().createId(“ExtensionLabelId”), {
                                    items: {
                                        path: "{ComboBoxModel>/}",
                                        template: new sap.ui.core.Item({
                                            key: "{ComboBoxModel>CUSTOMER_NAME}",
                                            text: "{ComboBoxModel>CUSTOMER_NAME}"
                                        })
                                    },
                                    value : "{model2>/"+ keys[i] + "/fieldvalue}",
                                    enabled: false
                                }));
                    },
                    error: function(error)
                    {
                        console.log("Error Message : " + JSON.stringify(error));
                    }
                });

Currently I am developing of SAPUI5 application, in my page. I have to create ComboBox dynamically based on data from microservices.

i follow sample code from following url. view-source:https://sapui5.hana.ondemand./test-resources/sap/m/ComboBox.html

However, it return me empty in my bobox

The following is my sample code.

$.ajax({
                    url: "json/customers.json", 
                    dataType: 'json',
                    success: function(response){
                        var data= response; 
                        console.log(data);
                        var customerModel = new JSONModel(data);
                        console.log(customerModel);
                        oController.getView().setModel(customerModel, "customerJSON");
                        var ExtensionForm = oController.getView().byId("Extension_Form");

                                ExtensionForm.addContent(new sap.m.ComboBox(oController.getView().createId(“ExtensionLabelId”), {
                                    items: {
                                        path: "{ComboBoxModel>/}",
                                        template: new sap.ui.core.Item({
                                            key: "{ComboBoxModel>CUSTOMER_NAME}",
                                            text: "{ComboBoxModel>CUSTOMER_NAME}"
                                        })
                                    },
                                    value : "{model2>/"+ keys[i] + "/fieldvalue}",
                                    enabled: false
                                }));
                    },
                    error: function(error)
                    {
                        console.log("Error Message : " + JSON.stringify(error));
                    }
                });
Share Improve this question edited Nov 13, 2018 at 8:07 Jaro 1,7541 gold badge16 silver badges36 bronze badges asked Oct 24, 2018 at 3:16 Chan Yoong HonChan Yoong Hon 1,8227 gold badges37 silver badges73 bronze badges 2
  • Kindly share your response data, I guess you have a binding path issue path: "{ComboBoxModel>/}" – Inizio Commented Oct 24, 2018 at 4:21
  • @inizio I solved it already. I just remove {} and i works perfectly now. – Chan Yoong Hon Commented Oct 24, 2018 at 5:48
Add a ment  | 

1 Answer 1

Reset to default 4

I solve it already. I just remove the curly brackets {} in path and now works perfectly for me.

The following is my code

$.ajax({
                    url: "json/customers.json", 
                    dataType: 'json',
                    success: function(response){
                        var data= response; 
                        console.log(data);
                        var customerModel = new JSONModel(data);
                        console.log(customerModel);
                        oController.getView().setModel(customerModel, "customerJSON");
                        var ExtensionForm = oController.getView().byId("Extension_Form");

                                ExtensionForm.addContent(new sap.m.ComboBox(oController.getView().createId(“ExtensionLabelId”), {
                                    items: {
                                        path: "ComboBoxModel>/",
                                        template: new sap.ui.core.Item({
                                            key: "{ComboBoxModel>CUSTOMER_NAME}",
                                            text: "{ComboBoxModel>CUSTOMER_NAME}"
                                        })
                                    },
                                    value : "{model2>/"+ keys[i] + "/fieldvalue}",
                                    enabled: false
                                }));
                    },
                    error: function(error)
                    {
                        console.log("Error Message : " + JSON.stringify(error));
                    }
                });
发布评论

评论列表(0)

  1. 暂无评论