3
我使用下面的代碼,此代碼工作正常。Knockout Js: - 使用刪除按鈕的標籤綁定
但我想在標籤檢查時需要,標籤綁定與刪除按鈕,並且還點擊刪除時,值取消選中。
這段代碼怎麼可能?
<div id="current-selected" style="" data-bind="text: selectedChoicesDelimited">
<a href="" id="clearAll" >Clear All</a>
</div>
<div data-role="content" class="filter-options-content" role="tabpanel" aria-hidden="false">
<ol class="items mcs-items" data-bind="foreach: choices">
<li>
<label>
<input id="5" class="multifilter" value="attribute?activity?5" type="checkbox" data-bind="attr: { value: $data }, checked: $parent.selectedChoices" ><span data-bind="text: $data"><input type="button" value="Remove Task" data-bind="click: $parent.removeChoices"></span>
</label>
</li>
</ol>
</div>
<script type="text/javascript">
var viewModel = {};
viewModel.choices = ["Outdoor", "Recreation", "Gym"];
viewModel.selectedChoices = ko.observableArray([]);
viewModel.selectedChoicesDelimited = ko.dependentObservable(function() {
return viewModel.selectedChoices().join(",");
});
ko.applyBindings(viewModel);
</script>
以下圖片中爲此代碼輸出。
下面的圖像,我想需要。點擊[x]時,取消選中。
哇,我知道了..謝謝了很多@MattKaaj .. –