我的问题更新我在这里有一个小提琴http://jsfiddle.net/googlegovind/4hLw86of/
var initialData = [{ "firstQuest": "",
"Options": [
{
"option": " ",
"coption": " "
}]
}];
var QuizModel = function(Questions) {
var self = this;
self.Questions = ko.observableArray(ko.utils.arrayMap(Questions, function(question) {
return { firstQuest: question.firstQuest,
// lastName: contact.lastName,
Options: ko.observableArray(question.option) };
}));
self.addQuest = function() {
self.Questions.push({
firstQuest: "",
Qtype:"",
Options: ko.observableArray()
});
};
self.removeQuest = function(question) {
self.Questions.remove(question);
};
self.addOption = function(question) {
question.Options.push({
option: " ",
coption: " "
// number: ""
});
};
self.removeOption = function(option) {
$.each(self.Questions(), function() { this.Options.remove(option) })
};
self.save = function() {
self.lastSavedJson(JSON.stringify(ko.toJS(self.Questions), null, 2));
};
self.lastSavedJson = ko.observable("");
};
ko.applyBindings(new QuizModel(initialData));
我想创建一个有不同问题和选项的quizmodel。小提琴正在工作,但我需要在点击下一个按钮时出现的不同视图中的每个问题,如果点击上一个,我需要返回并编辑每个问题。尝试了很多,但它没有工作.. atlast我想将这些数据保存到一个数组中(lastSavedJson中的数据)