0

我已经制作了许多函数,例如 $.redux.select 并且我想在触发 dialog_finished 事件时调用所有函数

这是 field_select.js 文件中的代码

(function($){
    "use strict";

    $.redux = $.redux || {};

    $(document).ready(function () {
        $.redux.select();
    });

    $.redux.select = function(){
        //some code here
    }   

})(jQuery);

这是 redux.js 文件中的代码

(function($){
    "use strict";

    $.redux = $.redux || {};

    $(document).ready(function () {

        var the_body = $(document);
        the_body.on('dialog_finished', function(event, window){
            //render all methods
            $.each($.redux, function( method, value ) {
                /*******************************************************************/
                   my problem is below , how to call $.redux.select() using $.each
                   or there is better way
                /*******************************************************************/
                $.redux.$method();
            });
        });

    });

})(jQuery);
4

1 回答 1

0
$.each($.redux, function( name, value ) {
    value();  // call the function
});

http://jsfiddle.net/EAgfP/

或者

$.each($.redux, function( name, value ) {
    $.redux[name]();  // call the function
});

http://jsfiddle.net/EAgfP/1/

于 2013-10-09T00:32:32.450 回答