Chaining multiple Select2 together

后端 未结 2 1935
借酒劲吻你
借酒劲吻你 2020-12-16 06:10

Trying to make two chained auto populating select fields using select2 plugin The first select contains countries names(static select) and the second shows the states of the

2条回答
  •  清酒与你
    2020-12-16 06:40

    you missed commas in json response.

    http://jsfiddle.net/jEADR/1570/

    var data = [{"id":"1","text":"Chigaco"},{"id":"4","text":"Albama"},{"id":"2","text":"Tulsa"}];
    var data2=[];
    $.map(data, function(item) {
          data2.push( { id: item.id, text: item.text }); 
    });
    $('#state').select2({
           data: data2
     });
    

提交回复
热议问题