gpt4 book ai didi

javascript - knockout : Uncaught TypeError: Object # has no method 'newCommentText'
转载 作者:塔克拉玛干 更新时间:2023-11-02 20:37:17 25 4
gpt4 key购买 nike

我的 View 模型中有这样的代码:

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));

但是当我尝试添加新评论时出现此错误:

enter image description here

任何想法我做错了什么?我在 knockoutjs.com 网页上查看了一些 knockout 样本,他们就是这样做的。

最佳答案

试试这个。

self.addComment = function(chat) {
var newComment = { CourseItemDescription: self.newCommentText() };
chat.CommentList.push(newComment);
self.newCommentText("");
};

您的 this 变量不是您所期望的。

希望这对您有所帮助。

关于javascript - knockout : Uncaught TypeError: Object #<Object> has no method 'newCommentText' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11022829/

25 4 0