Note that there are some explanatory texts on larger screens.

plurals
  1. POknockoutjs - ko not found
    primarykey
    data
    text
    <p>This is my knockoutjs code: </p> <pre><code>$(function () { function QuizViewModel() { var self = this; self.previousQuestions = ko.observableArray([]); self.questions = ko.observableArray([]); self.thisQuestion = ko.observable(); self.questionNumber = ko.observable(0); self.arrPreviousNumbers = ko.observableArray([]); self.selectedAnswers = ko.observableArray(); self.loadQuestions = function () { $('#allQuestions').fadeOut('fast'); $.getJSON('./json/quiz.json', function (data) { $.each(data, function (i, q) { self.questions.push(q); }); }); $('#questions').fadeIn('fast'); } self.getQuestion = function (number) { $.getJSON('./json/quiz.json', function (data) { $.each(data, function (i, q) { if (number == i) { self.thisQuestion(q); } }); }); } self.nextQuestion = function () { if (self.arrPreviousNumbers().length == 15) { $('#allQuestions').fadeIn('fast'); $('#questions').fadeOut('fast'); } else { var randomnumber = Math.floor(Math.random() * 15) if (self.arrPreviousNumbers.indexOf(randomnumber) == -1) { if (self.arrPreviousNumbers().length &gt; 0) { self.thisQuestion().selectedAnswers = self.selectedAnswers(); alert(self.thisQuestion().selectedAnswers[0]); self.previousQuestions.push(self.thisQuestion()); self.selectedAnswers.removeAll(); } self.arrPreviousNumbers.push(randomnumber); self.getQuestion(randomnumber); var previousNumber = self.questionNumber(); self.questionNumber(previousNumber + 1); } else { self.nextQuestion(); } } } $('#allQuestions').fadeOut('fast'); self.nextQuestion(); } ko.applyBindings(new QuizViewModel()); }); </code></pre> <p>and this is my html5 page:</p> <pre><code>... &lt;div id ="questions" data-bind="with: thisQuestion"&gt; &lt;h2&gt;Question&lt;/h2&gt; &lt;p data-bind="text: question"&gt;&lt;/p&gt; &lt;div class="answers"data-bind="foreach: answers"&gt; &lt;p data-bind="with: $data"&gt; &lt;input type="radio" data-bind="checked: $root.selectedAnswers, value: title"/&gt; &lt;span data-bind="text: title"&gt;&lt;/span&gt; &lt;/p&gt; &lt;/div&gt; &lt;p data-bind="text: info"&gt;&lt;/p&gt; &lt;button data-bind="click: $root.nextQuestion"&gt; blabla &lt;/button&gt; &lt;/div&gt; &lt;div id ="allQuestions"&gt; &lt;h2&gt;Correction&lt;/h2&gt; &lt;div class ="answers"&gt; &lt;div data-bind="foreach: previousQuestions"&gt; &lt;p data-bind="text: question"&gt;&lt;/p&gt; &lt;div data-bind="foreach: selectedAnswers"&gt; &lt;span data-bind="text: $data"&gt;&lt;/span&gt; &lt;/div&gt; &lt;div data-bind="foreach: answers"&gt; &lt;p data-bind="with: $data"&gt; &lt;input type="radio" data-bind="value: title, checked: status=='true'" disabled="true"/&gt; &lt;span data-bind="text: title"&gt; &lt;/span&gt;&lt;span data-bind="checked: $parent.selectedAnswers"&gt;&lt;/span&gt;&lt;!--&lt;span data-bind="text: $parent.selectedAnswers"&gt; &lt;/span&gt;--&gt; &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;script type='text/javascript' src='js/libs/knockout-2.0.0.js'&gt;&lt;/script&gt; &lt;script defer src="js/plugins.js"&gt;&lt;/script&gt; &lt;script src="js/quiz.js"&gt;&lt;/script&gt; ... </code></pre> <p>the last part in my kojs file: ko.applyBindings(new QuizViewModel()); has an error: Uncaught ReferenceError: ko is not defined. Can someone help me with this ? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload