on 05-18-2018 7:27 PM
Hi community, i'm triying to load some data from my json to a combobox but nothing happend
error:
jquery.sap.global-dbg.js:1035 2018-05-18 14:37:36.056399 The following problem occurred: parsererror - {
"V_ADRCTPRT" : [ {
"cod_comuna": "1000005", "cod_pob": "02101", "nomb_comuna": "ANTOFAGASTA", "ciudad": "ANTOFAGASTA", "region": 02"
"cod_comuna": "1000005", "cod_pob": "02102", "nomb_comuna": "MEJILLONES", "ciudad": "ANTOFAGASTA", "region": 02"
"cod_comuna": "1000005", "cod_pob": "02103", "nomb_comuna": "SIERRA GORDA", "ciudad": "ANTOFAGASTA", "region": 02"
"cod_comuna": "1000005", "cod_pob": "02104", "nomb_comuna": "TALTAL", "ciudad": "ANTOFAGASTA", "region": 02"
} ]
},200,OK
my structure just in case
this is my data: (comunas.json)
{ "V_ADRCTPRT" : [
{"cod_comuna": "1000005", "cod_pob": "02101", "nomb_comuna": "ANTOFAGASTA", "ciudad": "ANTOFAGASTA", "region": "02"},
{"cod_comuna": "1000005", "cod_pob": "02102", "nomb_comuna": "MEJILLONES", "ciudad": "ANTOFAGASTA", "region": "02"},
{"cod_comuna": "1000005", "cod_pob": "02103", "nomb_comuna": "SIERRA GORDA", "ciudad": "ANTOFAGASTA", "region": "02"},
{"cod_comuna": "1000005", "cod_pob": "02104", "nomb_comuna": "TALTAL", "ciudad": "ANTOFAGASTA", "region": "02"}
]
}
this is my view:
<ComboBox showSecondaryValues= "true"
items="{path: '/oModelComunas/V_ADRCTPRT'}">
<core:ListItem key="{cod_comuna}-{cod_pob}" text="{nomb_comuna}" additionalText = "{ciudad}"/>
</ComboBox>
and in my controller i don't know how to load the data
var oModelComunas = new JSONModel(jQuery.sap.getModulePath("crm.prospecto", "/model/comunas.json"));
this.getView().setModel(oModelComunas);
First, load the json to your local variable using the loadData method of the JSON model.
var localData = new sap.ui.model.json.JSONModel();
localData.loadData("model/comunas.json");
// Before you proceed, test in debugger, if your data from local json is loaded in the local vairable localData.
Then, set the data to view
this.getView().setModel(localData);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
look i send the model to my combobox
<ComboBox id="comboComuna"
showSecondaryValues= "true"
items="{path: '/localData/V_ADRCTPRT/'}">
<core:ListItem key="{cod_comuna} - {cod_pob}" text="{nomb_comuna}" additionalText = "{ciudad}"/>
</ComboBox>
and my controller:
var localData = new JSONModel();
localData.loadData("model/comunas.json");
this.getView().byId("comboComuna").setModel(localData);
and i'm no getting any error of this and my data is loading god, look:
i know what was the problem , if i sent my model i was rewriting the model again in my combo box
items="{path: '/V_ADRCTPRT'}" Ok
items="{path: '/localData/V_ADRCTPRT'}"> Not Ok
and the controller was fine
var localData = new JSONModel();
localData.loadData("model/comunas.json");
this.getView().byId("comboComuna").setModel(localData);
Hi Naoto
There is issue with your items bindingthere shouldnot be "/" for /oModelComunas/V_ADRCTPRT . I think your model is named model so it should be like oModelComunas>/V_ADRCTPRT.
Another issue is you have not mentioned the row to be binded here . It should be like oModelComunas/0/V_ADRCTPRT. This should solve your issue please check.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.