0

This is my last knockout question :)

I have an if statement setup and is working when the page is loaded for the first time however whenever I try adding any new items to my view model the if statement is not fired.

My JS fiddle

Why does it work when I initialize the viewmodel the first time however not when adding other items. I dont get any errors

4

1 回答 1

0

您需要在 qtype 上使用括号作为 if 表达式的一部分,即:

<!-- ko if: qtype() === 'Rating' -->

另外,您不想让您的 arrayMap 迭代器返回您的 Question 视图模型的实例吗?IE:

self.questions = ko.observableArray(ko.utils.arrayMap(questions, function(question) {
    return new Question(question.question, question.qtype);
}));

这是一个更新的小提琴:

http://jsfiddle.net/wR6mb/15/

于 2012-08-05T10:55:56.810 回答