我正在尝试在metabox中使用media manager,我需要使用multiple select。我只是对从那个选择中输出有问题。我需要metabox中的元素来保存所有选定的文件URL。我的代码在这里:
jQuery(document).ready(function($){
var custom_uploader;
$(\'#upload_image_button\').click(function(e) {
e.preventDefault();
//If the uploader object has already been created, reopen the dialog
if (custom_uploader) {
custom_uploader.open();
return;
}
//Extend the wp.media object
custom_uploader = wp.media.frames.file_frame = wp.media({
title: \'Choose Image\',
button: {
text: \'Choose Image\'
},
multiple: true
});
custom_uploader.on(\'select\', function() {
selection.map( function( attachment ) {
attachment = attachment.toJSON();
$("#obal").after("<img src=" +attachment.url+">");
});
});
custom_uploader.open();
});
});
怎么了?
最合适的回答,由SO网友:sjiamnocna 整理而成
这只是我的错误。。。我忘了改进var selection
jQuery(document).ready(function($){
var custom_uploader;
$(\'#upload_image_button\').click(function(e) {
e.preventDefault();
//If the uploader object has already been created, reopen the dialog
if (custom_uploader) {
custom_uploader.open();
return;
}
//Extend the wp.media object
custom_uploader = wp.media.frames.file_frame = wp.media({
title: \'Choose Image\',
button: {
text: \'Choose Image\'
},
multiple: true
});
custom_uploader.on(\'select\', function() {
var selection = custom_uploader.state().get(\'selection\');
selection.map( function( attachment ) {
attachment = attachment.toJSON();
$("#obal").after("<img src=" +attachment.url+">");
});
});
custom_uploader.open();
});
});