Aurelia trying to load HTML from Select2?

后端 未结 2 1397
-上瘾入骨i
-上瘾入骨i 2020-12-21 05:09

So I\'m trying to use Select2 within my Aurelia application. I installed Select2 using jspm install select2, and within my app.html file I require

2条回答
  •  暖寄归人
    2020-12-21 05:42

    For the sake of completion, firing the change event in Jeremy's solution results in a recursive loop and causes exception to fix it I had to do:

    attached() {
        $(this.element)
         .select2(this.value)
         .on('change', evt => {
             if (evt.originalEvent) { return; }
             this.element.dispatchEvent(new Event('change'));
         });
    }
    

    I could then do:

    
    
    
    

    changeCallback($event) can be a function on your vm e.g.

    changeCallback(evt: Event): void {
        console.log(evt);
    }
    

提交回复
热议问题