我是Knockout js的新手,我在按鈕單擊事件中發現了一個問題。我有一個列表,其中每個列表項都有一個用於評論的按鈕。當我點擊按鈕時,不可見的評論框應該是可見的。以下是我的HTML代碼:敲除單擊事件可見狀態
<ul class="unstyled list" data-bind="foreach: filteredItems">
<li>
<input type="checkbox" value="true" data-bind =" attr: { id: id }" name="checkbox" class="checkbox">
<label class="checkbox-label" data-bind="text: title, attr: { for: id }"></label>
<button class="pull-right icon" data-bind="click: loadComment, attr: { id: 'btn_' + id }"><img src="../../../../../Content/images/pencil.png" /></button>
<div class="description" data-bind="visible: commentVisible, attr: { id : 'item_' + id}">
<textarea data-bind="value: comment" class="input-block-level" rows="1" placeholder="Comment" name="comment"></textarea>
<div class="action">
<button class="accept" data-bind="click: addComment">
<img src="../../../../../Content/images/accept.png" /></button>
<button class="cancel" data-bind="click: cancel">
<img src="../../../../../Content/images/cancel.png" /></button>
</div>
</div>
</li>
</ul>
在我看來模型中,我已經提到點擊loadComment
時,評論應該是可見
var filteredItems = ko.observableArray([]),
filter = ko.observable(),
items = ko.observableArray([]),
self = this;
self.commentVisible = ko.observable(false);
self.comment = ko.observable();
self.addComment = ko.observable(true);
self.cancel = ko.observable();
self.loadComment = function (item) {
self.commentVisible(true);
}
問題是,當我點擊loadComment按鈕,所有的評論每個列表項目中的框都可見。我只想讓只有點擊按鈕的評論框出現。
需要一些幫助。
謝謝
請包括其他相關的代碼。有用的將是commentVisible聲明,甚至可能是filteredItems的聲明。顯示問題的實例將是最好的。 –
@ Gary.S我添加了聲明。 – Mujahid