Select to view content in your preferred language

Dojo Store/ Combobox

1572
6
Jump to solution
01-31-2019 04:27 AM
AlbertoCañivano
New Contributor III

Good morning
I have the data returned from a query through esri/request and I want to pass them to a Combobox to show me in the drop-down menu these data. I am using dojo/store/memory and dijit/form/Combobox.

I am basing myself on this example
https://dojotoolkit.org/reference-guide/1.10/dijit/form/ComboBox.html
but in my case, the values I want to introduce are extracted from an XML file.

Just as I'm stressing it and I don't know if it's correct, I've looped over the
returned query to get the values I'm interested in. Inside this loop I have generated the variable "stateStore" that will keep the query data.
Then I create the Combobox that will show the names of the query.

var resp_prov_name = response.getElementsByTagName('np');

var i;
          for (i=0; i< resp_prov_name.length; i++){

            //busca nombre provincia
          dom.byId("status").value = xmlParser.textContent(resp_prov_name[i]);
          var resp_prov_name1 = dom.byId("status");
          this.resp_prov_name1=resp_prov_name1.value
          
          
            var stateStore = new Memory({
                data: this.resp_prov_name1, 
            });
                                   
            }; 

            var comboBox = new ComboBox({
              name: this.resp_prov_name1,
              value: "",
              store: stateStore,
              searchAttr: "name"
            },"stateSelect").startup();
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I have doubts about whether it is necessary to create the loop I have made. As I have it now, if I put the ComboBox inside the loop. it fills in the first value of the query but gives error because the widget is already created.
If I take it out of the loop, it only completes one value of the Combobox.
Thank you very much for your help

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Alberto,

  By the way my Name is Robert not Richard. You are not paying attention to the dojo code sample link you provided. When you push the data to the array in the loop is where you have to create the object Not when assigning it to the Memory data property.

var resp_prov_name = response.getElementsByTagName('np');

var provincias_name = [];
var i;
for (i=0; i< resp_prov_name.length; i++){
  //busca nombre provincia
  dom.byId("status").value = xmlParser.textContent(resp_prov_name[i]);
  var resp_prov_name1 = dom.byId("status");
  this.resp_prov_name1=resp_prov_name1.value;
  provincias_name.push({name:this.resp_prov_name1, value:this.resp_prov_name1});
});
                                   
var provinciaStore = new Memory({
  data:provincias_name
});

var comboBox = new ComboBox({
  id: "provinciasName",
  name: "provincias_name",
  value: "",
  store: provinciaStore,
  searchAttr: "name"
},"stateSelect").startup();‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus

Alberto,

   So you need to loop through your resp_prov_name array but you do not need to create the combobox untill after you are out of the loop. Inside the loop you need to add the xmlParser.textContent(resp_prov_name) value to a new array and then out side the loop add that new array to the new Memory data property.

0 Kudos
AlbertoCañivano
New Contributor III

I've done the part you told me about.

However, when running it, it it seems that I am not putting any value to the Combo, because the browser console gives me the following error: "TypeError: Cannot read property 'toString' of undefined"

Do you know what that might be due to?

var resp_prov_name = response.getElementsByTagName('np');

var provincias_name = [];
var i;
          for (i=0; i< resp_prov_name.length; i++){

            //busca nombre provincia
            dom.byId("status").value = xmlParser.textContent(resp_prov_name[i]);
            var resp_prov_name1 = dom.byId("status");
            this.resp_prov_name1=resp_prov_name1.value  
            provincias_name.push(this.resp_prov_name1) 
          });
                                   
var stateStore = new Memory({
         data:provincias_name
              
});

var comboBox = new ComboBox({
              id: "stateSelect",
              //name: "provincias_name",
              value: "Elija provincia",
              store: stateStore,
              //searchAttr: "name"
            },"stateSelect").startup();‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alberto,

  So your issue is that you are adding a simple string to the array that you are using for the Memory object. The sample you linked shows you that you need to be creating an Object with a name and id property.

0 Kudos
AlbertoCañivano
New Contributor III

Richard. I am trying to put into Memory two arrays; provincias_name and provincias_id.
Thinking that in this way the tool allows me to make the dropdown with all the provinces I have in the array. In fact the tool works but showing in a single line all the content of the array.
In which way do you think I could go through the array to do it correctly?
Maybe it's not the tool I need. Thanks

var stateStore = new Memory({
              data: [
                  {name: provincias_name, id: provincias_id} 
              ]
              
              });‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

var comboBox = new ComboBox({
              
              id: "stateSelect",
              name: "Estados",
              value: "Elija provincia",
              store: stateStore,
              //searchAttr: "name"
            },"stateSelect").startup();
            
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alberto,

  By the way my Name is Robert not Richard. You are not paying attention to the dojo code sample link you provided. When you push the data to the array in the loop is where you have to create the object Not when assigning it to the Memory data property.

var resp_prov_name = response.getElementsByTagName('np');

var provincias_name = [];
var i;
for (i=0; i< resp_prov_name.length; i++){
  //busca nombre provincia
  dom.byId("status").value = xmlParser.textContent(resp_prov_name[i]);
  var resp_prov_name1 = dom.byId("status");
  this.resp_prov_name1=resp_prov_name1.value;
  provincias_name.push({name:this.resp_prov_name1, value:this.resp_prov_name1});
});
                                   
var provinciaStore = new Memory({
  data:provincias_name
});

var comboBox = new ComboBox({
  id: "provinciasName",
  name: "provincias_name",
  value: "",
  store: provinciaStore,
  searchAttr: "name"
},"stateSelect").startup();‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
AlbertoCañivano
New Contributor III

I'm sorry, Robert. And thank you for your invaluable help. Code working!

0 Kudos