関連するコードは次のとおりです。
<div data-bind="foreach: chats, visible: chats().length > 0">
<input data-bind='value: $parent.newCommentText' />
<a href="#" data-bind='click: $root.addComment'>Add comment</a>
</div>
ViewModel:
self.newCommentText = ko.observable()
self.addComment = function(chat) {
var newComment = { CourseItemDescription: self.newCommentText(), };
chat.CommentList.push(newComment);
self.newCommentText("");
$.ajax({
url: "@Url.Action("AddComment")",
data: ko.toJSON(newComment),
type: "post",
contentType: "application/json"
});
};
問題は、これにより、1つのテキストボックスに入力したものが他のすべてのテキストボックスに配置されることです。ユーザーが入力しているテキストボックスにのみバインドし、そのデータをaddComment関数で使用できるようにするにはどうすればよいですか?