admin管理员组文章数量:1420939
I have code like this in my view model:
function ChatListViewModel(chats) {
var self = this;
self.newCommentText = ko.observable();
self.addComment = function(chat) {
var newComment = { CourseItemDescription: this.newCommentText() };
chat.CommentList.push(newComment);
self.newCommentText("");
};
}
ko.applyBindings(new ChatListViewModel(initialData));
but I get this error when I try to add a new ment:
any Ideas what I'm doing wrong? I looked at some knockout samples on the knockoutjs webpage and this is how they were doing it.
I have code like this in my view model:
function ChatListViewModel(chats) {
var self = this;
self.newCommentText = ko.observable();
self.addComment = function(chat) {
var newComment = { CourseItemDescription: this.newCommentText() };
chat.CommentList.push(newComment);
self.newCommentText("");
};
}
ko.applyBindings(new ChatListViewModel(initialData));
but I get this error when I try to add a new ment:
any Ideas what I'm doing wrong? I looked at some knockout samples on the knockoutjs. webpage and this is how they were doing it.
Share Improve this question asked Jun 13, 2012 at 20:29 ladookieladookie 1,3714 gold badges21 silver badges25 bronze badges1 Answer
Reset to default 5Try this.
self.addComment = function(chat) {
var newComment = { CourseItemDescription: self.newCommentText() };
chat.CommentList.push(newComment);
self.newCommentText("");
};
Your this variable is not what you expect.
Hope this helps.
版权声明:本文标题:javascript - knockout: Uncaught TypeError: Object #<Object> has no method 'newCommentText' - Stack 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745322852a2653455.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论