列表框在wordpress3.9中返回错误的值 [英] listbox return wrong value in wordpress3.9

查看:130
本文介绍了列表框在wordpress3.9中返回错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Wordpress 3.8中使用了列表框UI元素,但在其较新版本(3.9)中不起作用.我编写了以下JS代码进行测试:

I used the listbox UI element in Wordpress 3.8, but it does not work in its newer version (3.9). I wrote this JS code to test it:

(function() {
var ICONS;
var icon = function(id) {
    return '<i class="fa fa-' + id + '"></i>';
}

ICONS = ["rub", "ruble", "rouble", "pagelines", "stack-exchange", "arrow-circle-o-right", "arrow-circle-o-left", "caret-square-o-left", "toggle-left", "dot-circle-o", "wheelchair", "vimeo-square", "try", "adjust", "anchor", "archive", "arrows", "arrows-h", "arrows-v", "asterisk", "ban", "bar-chart-o", "barcode", "bars", "beer", "bell", "bell-o", "bolt", "book", "bookmark", "bookmark-o", "briefcase", "bug"]

var menuval=[];
for (var i = 0; i < ICONS.length; i++) {
    var _id = ICONS[i];
    menuval.push({text: icon( _id )+' '+_id, onclick: function(){setcontentfun(_id)} 
 });
}

tinymce.PluginManager.add("font_awesome_glyphs", function(editor, url) {
    var menucreate=editor.addButton('fontAwesomeGlyphSelect', {
       type: 'listbox',
       text: 'Icons',
       icon: false,
       values: menuval
 });
});

function setcontentfun(id) {
    alert(id);
    return false;
} 
})();

这创建了一个显示的列表框,但是当我单击菜单项而不是警告"ICON"数组的最后一个元素时,它将显示列表框中的所有元素.如何提醒我单击的列表项?

This created displayed a listbox, but when I click on a menu item instead of alerting the last element of "ICON" array it displays all elements in listbox. How can I alert the list item, which I clicked?

推荐答案

只需在您的代码中进行一些更新:

Just did some updates in your code:

var menuval=[];
var insertVar = function (val) {
    return function () { 
        editor.insertContent(val);
    }
};
for (var i = 0; i < SHORTCODES.length; i++) {
    var _id = SHORTCODES[i];
    var _code = SHORTCODE_EXE[i];
    var variable = insertVar(_code);
    //alert(_id+' '+ SHORTCODES[i]+' '+SHORTCODE_EXE[i]);
    menuval.push({text: _id, onclick: variable }); 
}

这篇关于列表框在wordpress3.9中返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆