lad*_*kie 4 javascript knockout.js
我的视图模型中有这样的代码:
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));
Run Code Online (Sandbox Code Playgroud)
但是当我尝试添加新评论时出现此错误:

任何想法我做错了什么?我在knockoutjs.com网页上查看了一些淘汰样本,这就是他们这样做的方式.
试试这个.
self.addComment = function(chat) {
var newComment = { CourseItemDescription: self.newCommentText() };
chat.CommentList.push(newComment);
self.newCommentText("");
};
Run Code Online (Sandbox Code Playgroud)
你的这个变量不是你所期望的.
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
5409 次 |
| 最近记录: |