2012-06-21 19 views
0

我actualilly試圖TU使用這個漂亮的小工具:http://quasipartikel.at/multiselect_next/刷新JQuery用戶界面的Widget多選

我有兩個這樣的Widget在同一個頁面,而我想要做的就是刷新第二個當我選擇或取消選擇第一個項目。

對於爲例,在beggining,我只有這一點:

<select id="crc" class="multiselect" multiple="multiple"> 

</select> 

然後,選擇和取消的事件,我創建了一些更多的節點,並把它們添加到這一點(和它的作品,它創建這樣的事情:

<select id="crc" class="multiselect" multiple="multiple"> 
     <option>test1</option> 
     <option>test2</option> 
    </select> 

的問題是,我不能添加新的選項後刷新第二小 我發現那位一個有用的職位有類似的問題,並試圖這樣:

$("#crc").multiselect("destroy").multiselect(); 

但它沒有工作,有沒有人有想法?

回答

1

我有完全相同的問題。下面是我工作:

要解決問題ui.multiselect的析構函數進行以下更改內部的破壞功能:

destroy: function() { 
    this.element.show(); 
    this.container.remove(); 

    if ($.Widget === undefined) 
     $.widget.prototype.destroy.apply(this, arguments); 
    else { 
     $.Widget.prototype.destroy.apply(this, arguments); 
     return this; 
    } 
} 

舊的版本是:

destroy: function() { 
    this.element.show(); 
    this.container.remove(); 
    $.widget.prototype.destroy.apply(this, arguments); 
} 

原因這種變化是jQuery 1.8中引入的一個新的$ .Widget。我還做了以下更改/添加,以便它與IE9兼容,並且還提供了獲取selectedTexts的功能。

// get all selected values in an array 
selectedValues: function() { 
    return $.map(this.element.find('option[selected]=selected'), function(item,i) { return $(item).val(); }); 
}, 
selectedTexts: function() { 
    return $.map(this.element.find('option[selected]=selected'), function (item, i) { return $(item).html(); }); 
}