Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your code looks incomplete, So just added missing parts. With following code I could see Goals and Steps views being rendered. Let me know if your code is some thing different.</p> <pre><code>$(function () { window.Step = Backbone.Model.extend({ }) window.Steps = Backbone.Collection.extend({ model:window.Step, url: 'data/steps.json' }) window.Goal = Backbone.Model.extend({ defaults: { description: null }, initialize: function () { this.steps = new Steps(); this.steps.fetch({ reset: true }); this.stepsAll = new StepsViewForGoals({ collection: this.steps }); $('.all-steps').append(this.stepsAll.render().el); } }); window.Goals = Backbone.Collection.extend({ model: Goal, url: 'data/goals.json' }); window.goals = new Goals(); }); $(function () { window.GoalView = Backbone.View.extend({ className: 'list-item', template: _.template($('#goal-item-template').html()), initialize: function () { _.bindAll(this, 'render'); this.model.bind('change', this.render); }, render: function () { this.$el.html(this.template(this.model.toJSON())); return this; } }); window.GoalsView = Backbone.View.extend({ el: '#app', template: _.template($('#goals-list-template').html()), initialize: function () { _.bindAll(this, 'render'); this.collection.bind('reset', this.render); this.collection.bind('change', this.render); this.collection.bind('add', this.render); }, render: function () { this.$el.html(this.template()); this.collection.each(function (goal) { var view = new GoalView({ model: goal }); $('#goals').append(view.render().el); }); return this; } }); }); $(function () { window.StepView = Backbone.View.extend({ className: 'list-item', template: _.template($('#step-item-template').html()), initialize: function () { _.bindAll(this, 'render'); this.model.bind('change', this.render); }, render: function () { this.$el.html(this.template(this.model.toJSON())); console.log('Individual step'); return this; } }); window.StepsViewForGoals = Backbone.View.extend({ el: '.all-steps', template: _.template($('#step-list-template').html()), initialize: function () { _.bindAll(this, 'render'); this.collection.bind('reset', this.render); this.collection.bind('change', this.render); }, render: function () { this.$el.html(this.template()); console.log(this.collection.toJSON()); this.collection.each(function (step) { var view = new StepView({ model: step }); $('.all-steps-list').append(view.render().el); }); console.log('Steps View'); return this; } }); }); $(function () { var view = new window.GoalsView({ collection:window.goals }); view.render(); window.goals.fetch(); }) </code></pre>
 

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