admin管理员组文章数量:1195956
Here in a JS class, I used "wp.media" to upload images. I can open the media popup by clicking a button. But getting this error (Uncaught TypeError: Cannot read properties of undefined (reading 'state')) while submitting the image.
constructor ( btn ) {
super();
this.uploaderBtn = $( btn );
this.mediaFrame;
this.events();
}
events () {
this.uploaderBtn.on( 'click', this.upload.bind( this ) );
}
upload ( e ) {
e.preventDefault();
//If the uploader object has already been created, reopen the dialog
if ( this.mediaFrame ) {
this.mediaFrame.open();
return;
}
//Extend the wp.media object
this.mediaFrame = wp.media.frames.file_frame = wp.media({
title: 'Choose Image',
button: {
text: 'Choose Image'
},
multiple: true
});
this.mediaFrame.on('select', function() {
const selection = this.mediaFrame.state().get('selection');
console.log( selection );
});
this.mediaFrame.open();
}
本文标签: plugin developmentwpmedia Uncaught TypeError Cannot read properties of undefined (reading 39state39)
版权声明:本文标题:plugin development - wp.media Uncaught TypeError: Cannot read properties of undefined (reading 'state') 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738528494a2093135.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论