2016-07-05 1 views
0

後、私はこのイメージピッカーjQueryプラグイン(http://rvera.github.io/image-picker/)を使用していると私は、次のように問題に直面しています新しいデータでコントロールを選択:AJAX呼び出しの後に新しいデータで選択コントロールを再増殖再増殖画像ピッカーAJAX呼び出し

。詳細については

$.ajax({ 
    type: "GET", 
    url: requestURL, 
    dataType: 'json', 
    success: function(result) 
    { 
     $.each(result, function(i, obj) { 
     console.log(obj.description); 
     $('#cake-filling-types-select') 
      .append($("<option data-img-src='" + obj.image + "'></option>")           
      .attr("value", obj.code) 
      .text(obj.description)); 
    }); 
    $("#cake-filling-types-select").imagepicker({ 
     show_label : true 
    }); 

    $("#cake-filling-types-select").data("picker").sync_picker_with_select(); 
}}); 

ここでの問題を見つけてください:https://github.com/rvera/image-picker/issues/79

感謝を。

答えて

0

問題は解決しました。 @ArmindoMaurits @ GitHubの助けを借りて、 '$( "cake-filling-types-select")。empty();'このプラグインの選択をクリアするには問題ありません。

また、一部の項目が選択コントロールに表示されないその他の問題については、img srcがない項目が見つかりました。

更新作業コード:

 `$.ajax({ 
      type: "GET", 
      url: requestURL, 
      dataType: 'json', 
      success: function(result){ 

       $("#cake-filling-types-select").empty(); 

       $.each(result, function(i, obj) { 

        if(obj.image != null) 
        { 
         var imgSrc = obj.image; 
        }else{ 
         imgSrc = ''; 
        } 

      $('#cake-filling-types-select') 
       .append($("<option data-img-src='" + imgSrc + "'></option>") 
         .attr("value", obj.code) 
         .text(obj.description)); 
       }); 

       $("#cake-filling-types-select").imagepicker({ 
        show_label : true 
       }); 

      }});`