jQuery UI小部件返回jQuery包装对象而不是值

时间:2011-11-15 15:42:44

标签: jquery jquery-ui

我有一个jQuery UI自定义小部件:

$.widget('ui.objectpicker', {
    _init: function() {
        this.memberList = [/* ... */];
        // ...
    }

    // ...

    getMemberList: function() {
        // this correctly logs the value I wish to return
        console.log(this.memberList);
        return this.memberList;
    }
}

但是当我使用上面的代码时,它返回jQuery包装的对象而不是成员列表(JS fiddle):

$('#my-item').objectpicker('getMemberList');
// logs 'this.memberList', but returns the $('#my-item') object

如何返回this.memberList而不是$('#my-item')

1 个答案:

答案 0 :(得分:0)

看起来我的问题是我陈旧的jQuery / jQuery-UI版本。我正在运行jQuery UI 1.7,并且提供此功能的小部件工厂直到1.8才会降落(对于此提示,#jquery IRC频道上的< ajpiano> thnx)。

您可以看到示例here