Skip to Content

how to load data json to combobox

Hi community, i'm triying to load some data from my json to a combobox but nothing happend

error: 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"
	} ]

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}"/>

and in my controller i don't know how to load the data

var oModelComunas = new JSONModel("crm.prospecto", "/model/comunas.json"));

structur.png (6.6 kB)
Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    May 18, 2018 at 06:39 PM

    First, load the json to your local variable using the loadData method of the JSON model.

    var localData = new sap.ui.model.json.JSONModel();
    // 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
    Add comment
    10|10000 characters needed characters exceeded

    • 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();
  • May 21, 2018 at 04:19 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded