rvera / image-picker

Image Picker is a simple jQuery plugin that transforms a select element into a more user friendly graphical interface.
http://rvera.github.com/image-picker
Other
906 stars 216 forks source link

how to dynamic add a option to select ,use initialized but select is correct,but img not display.what can i do? #16

Closed javayunsky closed 10 years ago

javayunsky commented 10 years ago

$("#spaceToolsSelect").imagepicker({ hide_select: true, show_label: true, initialized:function(){

                var selectToolType = $("#selectToolType option:selected").val();
                $.getJSON(basePath+'/tool/getToolsByType.action?selectToolType='+selectToolType,function(jsonData){
                       $.each(jsonData, function (i, tool) {
                            // alert(tool.filePath);
                            //<option data-img-label="Awww" data-img-src="http://placekitten.com/220/200" value="1">Cute Kitten 1</option>
                            var toolName = tool.name;
                            var toolId = tool.id;
                            var toolPath = basePath+"/media/" + tool.filePath;
                            $("#spaceToolsSelect").append('<option data-img-label="'+toolName+'" data-img-src="'+toolPath+'" value="'+toolId+'">'+toolName+"</option>");
                             $(".controls thumbnails image_picker_selector").append('<li><div class="thumbnail"><img class="image_picker_image" src="'+toolPath+'"><p>"'+toolName+'"</p></div></li>');

                            });
                });

          }
    });
rvera commented 10 years ago

If you dynamically modify the select you have to reinitialize the image-picker by calling .imagepicker() again on the same select element.

I updated the docs to reflect this, go to the bottom of the page here:

http://rvera.github.io/image-picker/