javascript - js 对象键和值转换为单个字符串

标签 javascript php jquery wordpress

我的 WordPress 媒体 uploader 有问题,我正在选择多个图像,但问题是,我无法弄清楚如何将所有对象的键连接到单个字符串以存储到数据库中,任何帮助都会不胜感激,提前致谢...

附注我已经尝试过 $.each 但它返回一个错误,无法使用未定义的属性。

还有一件事:我在变量“attachment.url”上尝试了 console.log,这是日志:

http://localhost/wp3/wp-content/uploads/2015/01/long-shadow-logo-example.jpg
admin.js?ver=4.0.1:16 http://localhost/wp3/wp-content/uploads/2015/01/Firefox.png
admin.js?ver=4.0.1:16 http://localhost/wp3/wp-content/uploads/2015/01/fish-logo-designs-32.png

但是当我尝试将此值添加到文本框时,仅返回一个 url。

这是我的 JS 代码:

   jQuery(document).on("click", ".custom_media_upload", function(e) {
         e.preventDefault();
         var custom_uploader = wp.media({
             title: 'Select Images to Use',
             button: {
                 text: 'Use Selected Images',
             },
             multiple: true // Set this to true to allow multiple files to be selected
         })
         custom_uploader.on('select', function() {
             var selection = custom_uploader.state().get('selection');
             selection.map(function(attachment) {
                 attachment = attachment.toJSON();
                 console.log(attachment.url);

             });
             //custom_uploader.open();

         });
         custom_uploader.open();


     });

最佳答案

你已经使用了 jQuery(document),我认为 $.each 会起作用,如果你像这样改变 jQuery.each

关于javascript - js 对象键和值转换为单个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28207916/

相关文章:

javascript - 简单的图像 slider 不起作用(jQuery)

javascript - Angularjs - $uibModal 提供程序错误

php获取网站主机

php - 来自 Paypal 的 Laravel 5.1 csrftoken curl

php - '&=' 和 '=&' 运算符是做什么的?

离开页面前的 JavaScript

javascript - 通过点击 html 链接在谷歌地图上显示信息窗口

javascript - 仅当某些页面在 Angular 2 中设置为默认页面时,应用程序才会中断(仅限 Chrome)

javascript - catch 语句可以捕获 JavaScript 中的语法错误吗?

javascript - 是否可以将多个事件处理程序绑定(bind)到 JqGrid 事件而不覆盖以前的事件?