【发布时间】:2015-09-21 23:09:35
【问题描述】:
我在 WYSIWYG 中添加了一个按钮,该按钮会打开一个弹出窗口,其中包含要填写的字段。对于这些字段,我正在尝试添加另一个按钮,该按钮将从媒体库中选择一个文件并将链接/url 插入文本字段中.我的按钮可以工作,它会打开媒体库,但是当我选择一个文件时,文本字段中没有插入任何内容。
如果我在媒体选择后为 json.url 添加警报,它会提醒我文件链接,所以我知道它正在从文件中获取 url。但是,我无法将其放入文本字段。
这是我的editor_plugin.js 文件中的一段代码:
{
type: 'textbox',
name: 'myfile',
label: 'My File',
id: 'my-file',
value: ''
},{
type: 'button',
name: 'select-file',
text: 'Upload File',
onclick: function() {
window.mb = window.mb || {};
window.mb.frame = wp.media({
frame: 'post',
state: 'insert',
library : {
type : 'image'
},
multiple: false
});
window.mb.frame.on('select', function() {
var json = window.mb.frame.state().get('selection').first().toJSON();
alert(json.url);
if (0 > $.trim(json.url.length)) {
return;
}
$('#my-file').val(json.url);
});
window.mb.frame.open();
}
}
【问题讨论】: