是否可以访问JQuery插件的内部属性?

时间:2010-05-18 02:34:10

标签: javascript jquery jquery-plugins dictionary properties

我正在尝试根据用户操作更改此插件中的 extraParams

var t = new $.TextboxList('#entSearch', {unique: true, plugins: {
            autocomplete: {
                minLength: 3,
                queryRemote: true, 
                placeholder: false, 
                remote: {
                    url: "{{=URL(r=request, f='call/json/suggest')}}", 
                    extraParams: {type: "", guid: ""}
                    }
                }
            }
        });

执行以下行会引发错误: autocomplete.remote未定义

var tmp = autocomplete['remote']['extraParams']['type'];

有没有办法访问插件的这些内部属性,就像我在dict中引用它们一样?

1 个答案:

答案 0 :(得分:1)

将其定义为变量,以便日后访问。

var plugins = {
    autocomplete: {
        minLength: 3,
        queryRemote: true, 
        placeholder: false, 
        remote: {
            url: "{{=URL(r=request, f='call/json/suggest')}}", 
            extraParams: {type: "", guid: ""}
        }
    },
    t = new $.TextboxList('#entSearch', {unique: true, plugins: plugins});

然后您可以这样访问它:

var tmp = plugins.autocomplete.remote.extraParams.type;
// ... or ...
var tmp = plugins['autocomplete']['remote']['extraParams']['type'];