javascript - How to set Array in select -


i'm using selectize.js, have field in kind of search values ​​are set according array. array request , desire set him in select options. how can that?

html

<div id="wrapper">             <h1>selectize.js</h1>             <div class="demo">                 <div class="control-group">                     <label for="select-tools">tools:</label>                     <select id="select-tools" placeholder="buscar ag&ecirc;ncia..."></select>                 </div>             </div>         </div> 

this works

agenciasapi.getagencias().success(function (data) {     var embedded = data._embedded;     $scope.listaagencias = embedded.agencias;     alert(json.stringify($scope.listaagencias));   }).catch(function (error) {     alert("erro ao obter listagem de agencias");     console.log(json.stringify(error));   });     $('#select-tools').selectize({     maxitems: null,     valuefield: 'nome',     labelfield: 'nome',     searchfield: 'nome',     options: [       {nome: 'spectrometer'},       {nome: 'star chart'},       {nome: 'electrical tape'}     ],     create: false   }); 

enter image description here

but want this...

  agenciasapi.getagencias().success(function (data) {     var embedded = data._embedded;     $scope.listaagencias = embedded.agencias;     alert(json.stringify($scope.listaagencias));   }).catch(function (error) {     alert("erro ao obter listagem de agencias");     console.log(json.stringify(error));   });     $('#select-tools').selectize({     maxitems: null,     valuefield: 'nome',     labelfield: 'nome',     searchfield: 'nome',     options: $scope.listaagencias,     create: false   }); 

but doesn't works enter image description here

my $scope.listaagencias is

[    {       "nome":"agencia um",       "createdby":"anonymoususer",       "lastmodifiedby":"anonymoususer",       "createdat":"2015-07-21t12:15:36.369+0000",       "lastmodified":"2015-07-21t12:15:36.369+0000",       "_links":{          "self":{             "href":"http://localhost:8181/api/agencias/55ae37e8ccf2070af2e5ab1c"          }       }    },    {       "nome":"agencia dois",       "createdby":"anonymoususer",       "lastmodifiedby":"anonymoususer",       "createdat":"2015-07-21t12:15:41.286+0000",       "lastmodified":"2015-07-21t12:15:41.286+0000",       "_links":{          "self":{             "href":"http://localhost:8181/api/agencias/55ae37edccf2070af2e5ab1d"          }       }    }] 

i put inside request , works

  agenciasapi.getagencias().success(function (data) {     var embedded = data._embedded;     $scope.listaagencias = embedded.agencias;         $('#select-tools').selectize({         maxitems: null,         valuefield: 'nome',         labelfield: 'nome',         searchfield: 'nome',         options: embedded.agencias,         create: false       });      alert(json.stringify($scope.listaagencias));   }).catch(function (error) {     alert("erro ao obter listagem de agencias");     console.log(json.stringify(error));   }); 

enter image description here


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -