Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
162
rated 0 times [  168] [ 6]  / answers: 1 / hits: 116186  / 11 Years ago, thu, october 31, 2013, 12:00:00

I have a little problem. I'm using backbone.js. I wrote this code like in example:



<script>
$(document).ready(function () {
window.App = {
Views: {},
Models: {},
Collections: {}
}

App.Collections.Users = Backbone.Collection.extend({
model: App.Models.User,
url: 'service'
});
App.Models.User = Backbone.Model.extend({});

App.Views.App = Backbone.View.extend({
initialize: function() {
console.log( this.collection.toJSON() );
}
});

});
</script>


Than I started server and in browser console type this:



var x =new App.Collections.Users();
x.fetch()


And this follows to error: Uncaught TypeError: Cannot read property 'prototype' of undefined. But data is present in response. Details in picture. How to fix this?
Thanks for you answers.enter



enter


More From » jquery

 Answers
28

I fixed this bug. The problem was that I created Collection and then the Model. Collections use user model, as working unit, but when I defined this Collection, I did not define Model.



So, if you want to avoid this bug, firstly define a Model and only then define the Collection.


[#74592] Wednesday, October 30, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
julian

Total Points: 159
Total Questions: 105
Total Answers: 94

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;