0
我有一個將顯示產品列表的表單。以ui形式使用bootstrap-switch:重複
每個產品都可以選擇或取消選擇。用戶必須選擇他的產品,然後點擊繼續(提交)按鈕。
表示選中我已經使用http://www.bootstrap-switch.org/
我的問題是,在頁面加載時,一些產品都應該被默認選擇。
我對這個過程的代碼如下:
<ui:repeat value="#{bean.products}" var="product" varStatus="status">
<li>
<div>
<div>
<div>
<div style="width: 100%;">
<div>
<div><b>#{product.productName}</b></div>
</div>
<div>
<div class="make-switch switch-mini " data-on-label="Yes" data-off-label="No">
<input class="switch#{status.index}" type="checkbox"></input>
</div>
<input type="hidden" class="checked#{status.index}" value="#{product.initiallySelected}"></input>
</div>
</div>
</div>
</div>
</div>
</li>
</ui:repeat>
我的JavaScript需要最初選擇的產品標記爲「選中」,但沒有什麼我試過到目前爲止工作。這裏是我的JS:
$(document).ready(function() {
flipSwitches(0);
}
function flipSwitches(index) {
if ($(".checked"+index).length != 0) {
var b = $(".checked"+index).val();
alert(b);
if (b == "true" || b == true) {
alert("selected");
// $(".switch"+index).attr('checked', true);
// $(".switch"+index).bootstrapSwitch('toggleStatus');
// $(".switch"+index).bootstrapSwitch('status');
// $(".switch"+index).bootstrapSwitch('setState', true);
}
flipSwitches(index+1);
}
}
我使用JSF 2.1(Apache的MyFaces的2.1.5)和jQuery 2.0.2,在後臺一個Java bean。如果任何人都可以幫助我,或者指出我做錯了什麼,我會超級的!