2
간단하게 부트 스트랩 팝 오버 플러그인을 래핑하는 jquery UI 위젯을 작성하고 있습니다. 위젯에서 '단수'옵션 인 으로 전달할 수 있습니다. 전달 된 경우이 플러그인은 다른 모든 플러그인 인스턴스의 함수를 호출해야합니다.jquery ui 위젯의 모든 인스턴스에 대한 참조를 얻으시겠습니까?
이show: function(options){
options = options || {};
if(options.singular){
var instances = '????'; // how do I get all instances?
$.each(instances, function(i, o){
o.myWidget('hide');
});
}
this.element.popover('show');
}
그래서, 질문의 존재가 어떻게 위젯에 myWidget
이 모든 요소에 대한 참조를 얻을 것 :
뭔가 그래서
$('#one').myWidget();
$('#two').myWidget();
$('#three').myWidget();
$('#four').myWidget();
$('#one').myWidget('show'); //stuff from widget one is now visible
$('#two').myWidget('show'); //stuff from widget one and two are now visible
$('#three').myWidget('show'); //stuff from widget one, two and three are now visible
$('#two').myWidget('hide'); //stuff from widget one and three are now visible
$('#four').myWidget('show', {singular:true}); //stuff from widget four is now visible
처럼, 나는 쇼 기능처럼 보이는 상상 그들?
이러한 요소에 플러그인을 적용하면 인스턴스 작성자의 return this.each (function() {'에서 참조하고 있으므로'myWidget'과 같은 클래스를 제공하면' $ ('. myWidget'). each ('.. – Ohgodwhy
나는 위젯에 클래스를 배치 할 수 있으며, 각 클래스를 돌릴 수있다. - 코더가 데이터 속성을 배치 한 것을 본 적이있다. 선택자 –
그게 작동하고, 당신이 통제하지 않는 위젯의 모든 인스턴스에 대한 참조를 얻는 것은 어떨까요? (예 : UI의 진행 표시 줄 등) – Hailwood