This is my first Ember.js application. I am creating a multiple choice question (after all, a quiz). Whenever the submit button is pressed, it should highlight the selection as green for right or red for wrong. I get the error "Uncaught TypeError: undefined is not a function" on option.set ("highlight", "green") || option.set ("highlight", "red") in the file of my controllers /index.js. When I console.log (option), I see that there is an object with a property selected. What am I doing wrong?
routes / index.js
var IndexRoute = Ember.Route.extend({ model: function() { return Ember.A([ { question: "What up?", answer: 'option b', options: [ { text: "option a", active: false, highlight: '' }, { text: "option b", active: false, highlight: '1' } ] }, { question: "How many?", answer: 'two', options: [ "one", "two" ] } ]); } });
Controllers / index.js
var IndexController = Ember.ObjectController.extend({ actions:{ submitAction : function(){ this.get('model').forEach(function (item){ item.options.forEach(function (option) { if (option.text === item.answer) { console.log(option); option.set("highlight", "green"); console.log(option.highlight); } if (option.active && (option.text !== item.answer)) { option.set("highlight", "red"); } }); }); } } });
ltrainpr
source share