2012-10-31 12 views
0

我使用jQuery插件「雙面多選擇」按這裏: http://www.stevefenton.co.uk/cmsfiles/assets/File/twosidedmultiselect.html導軌和雙面多選擇的jQuery插件,奇怪的錯誤

使用這種常規的軌道助手成功顯示常規多選擇框代碼:

<%= f.select(:expertise1, Tag.all.collect {|tag| [ tag.value, tag.value ] }, {}, {multiple: true, class: "multiselect"}) %> 

我已經在我的資產的JavaScript文件夾中的文件jquery.twosidedmultiselector.js,並看到它在頁面的源代碼。 Jquery必須在整個地方使用它(導軌3.2.8)並且在源代碼中可見。 (1.8.2)

然而,當我加入這個給JavaScript(在$(文件)。就緒(函數()):

$(".multiselect").twosidedmultiselect(); 

我得到這個錯誤在JavaScript控制檯中,我有完全不知道這意味着什麼,以及如何解決它:

Uncaught TypeError: Object [object Object] has no method 'twosidedmultiselect' 

幫助!非常感謝

+0

移動下載腳本到文檔就緒功能(前)我的電話,使箱子顯示,但之間的按鈕不起作用... – bobomoreno

回答

-1

包住你的JavaScript在DOM就緒處理和要解決這個問題

$(function() { 
    // This is the only line you need for the plugin 
    $(".multiselect").twosidedmultiselect(); 

    // The below script is for information/example... 

    // How to get the current selected items (note, they won't always have 
    // a "selected" attribute, but they will be in the box with the original ID: 

    var selectedOptions = $("#yourselect")[0].options; 

}); 

你似乎在你的元素完全加載使用插件..編寫DOM處理程序中的代碼應該解決您的問題

+0

仍與我以前的評論相同;框顯示,但按鈕不工作,右側列表保持空白...有沒有人能夠得到這個與Rails合作?還嘗試了一個乾淨的Rails應用程序;即使文檔中沒有下載的代碼,它也能正常工作;但同樣的問題;按鈕不起作用,沒有任何反應。沒有JavaScript錯誤。嘆息,這是如此糟糕的記錄,任何人都知道任何替代品,實現與Rails相同? – bobomoreno

+1

得到了一切與multiselect.js http://loudev.com/ – bobomoreno

+0

這是一個很好的選擇謝謝!也許更新這個問題,所以更明顯。另外,要安裝multis,請在rails上選擇https://github.com/klenis/multi-select-rails。 – cgat