jQueryUI小部件返回jQuery包装的对象而不是值
我有一个jQuery UI自定义小部件:jQueryUI小部件返回jQuery包装的对象而不是值,jquery,jquery-ui,Jquery,Jquery Ui,我有一个jQuery UI自定义小部件: $.widget('ui.objectpicker', { _init: function() { this.memberList = [/* ... */]; // ... } // ... getMemberList: function() { // this correctly logs the value I wish to return cons
$.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包装的对象,而不是成员列表():
如何返回
this.memberList
而不是$(“#我的项目”)
?我的问题似乎是我的jQuery/jQuery UI的过时版本。我正在运行jQuery UI 1.7,而提供此功能的小部件工厂直到1.8(thnx到.您需要查看$.fn.widget的实现。它似乎为用户定义的方法添加了一个包装器。因此您的返回值将被忽略。我认为您需要更改$.fn.widget的原型
$('#my-item').objectpicker('getMemberList');
// logs 'this.memberList', but returns the $('#my-item') object