나는 이것이 가장 쉽고 빠르다고 느낀다. 그러나 적어도 나에게는 해결책이 도출하기 어렵다.확장 된 jquery 위젯 자동 완성의 프록시
기본적으로 일부 기능을 포함하도록 jQuery 자동 완성 위젯을 확장하려고합니다. select 이벤트에서 this.options.primaryField를 참조해야합니다. 여기
$.widget("mynamespace.myAutoComplete", $.ui.autocomplete, {
options: {
// our options
selectedId:0,
searchString:'',
indexField:'',
primaryField:'',
secondaryField:'',
// set existing ones
autoFocus: true,
minLength:3,
select: function(event,ui) {
// runs, but cant access this.options.<anything>
}
},
_myselect: function (event,ui) {
//does not run
console.log("in myselect");
},
_renderItem: function (ul, item) {
var icon='marker';
return $("<li>")
.append ('<div><a><i class=\"fi-' + icon + '"></i>' + item[this.options.primaryField] + "<br>" + item[this.options.secondaryField] + "</a><div>")
.appendTo (ul);
}
});
내가 찾은 가능한 해결책 : Howto access data held in widget options when inside a widget event handler, jQuery Widget Factory access options in a callback method 및 jQuery-ui: How do I access options from inside private functions
하지만 그들 중 하나가 동작하지 않습니다. 나는 단지 (자연적으로 $의 된 .widget에 추가 (... 클래스)
_create: function() {
// does not fire _myselect on select
this._on(this.select, { change: "_myselect"});
this._on(this.select, $.proxy(this._myselect, this));
this._on(this.select, $.bind(this._myselect, this));
this._super();
},
나는 또한뿐만 아니라 _init 함수들을 추가하는 시도했습니다. 이것은 내가 그 솔루션에서 파생 한 코드 항목을 클릭하면 this.options.selectedId,되는 searchString 등을 설정할 수 있도록하려면 사전에
감사