Created
August 7, 2013 20:43
-
-
Save shiroginne/6178459 to your computer and use it in GitHub Desktop.
ember.js app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App = Ember.Application.create(); | |
App.Router.map(function() { | |
this.resource("questions", { path: '/'}, function () { | |
this.resource("question", { path: ':question_id'}) | |
}); | |
this.resource("result") | |
}); | |
App.QuestionsRoute = Ember.Route.extend({ | |
setupController: function (controller, values) { | |
controller.set('model', App.Question.find()); | |
} | |
}); | |
App.ResultRoute = Ember.Route.extend({ | |
setupController: function(controller, song) { | |
controller.set('model', result); | |
} | |
}) | |
App.QuestionsController = Ember.ArrayController.extend({}); | |
App.ApplicationController = Ember.ObjectController.extend({ | |
calculatedResult: function () { | |
// How to get values from all Answers where isSelected is true? | |
}.property('calculatedResult') | |
}) | |
App.Store = DS.Store.extend({ | |
revision: 13, | |
adapter: DS.FixtureAdapter.create() | |
}); | |
App.Answer = DS.Model.extend({ | |
text: DS.attr('string'), | |
value: DS.attr('integer'), | |
isSelected: DS.attr('boolean') | |
}) | |
App.Question = DS.Model.extend({ | |
number: DS.attr('integer'), | |
text: DS.attr('string'), | |
answers: DS.hasMany('App.Answer') | |
}); | |
// FIXTURES | |
App.Answer.FIXTURES = [ | |
{ id: 1, text: 'test', value: 1}, | |
{ id: 2, text: 'some text', value: 0}, | |
{ id: 3, text: 'almost true', value: 7}, | |
{ id: 7, text: 'some critics', value: 3}, | |
{ id: 10, text: 'Kate and Leopold', value: 10, isSelected: true } | |
] | |
App.Question.FIXTURES = [ | |
{ id: 1, number: 1, text: 'To be or not to be?', answers: [1, 2]}, | |
{ id: 2, number: 2, text: 'Who is on duty today?', answers: [3, 7, 10]} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
but it render 0 :/