javascript - URL of collection is specified but it returns error -


i have collection on myapp.com/groups looking this:

[   {     "_id": "52dd2bd1044bf96a12ed2319",     "name": "us",     "id": 1,     "users": []   },   {     "_id": "52dd2bd1044bf96a12ed231b",     "name": "br",     "id": 3,     "users": []   },   {     "_id": "52dd2bd1044bf96a12ed231c",     "name": "sk",     "id": 4,     "users": []   },   {     "_id": "52dd2bd1044bf96a12ed231d",     "name": "cz",     "id": 5,     "users": []   },   {     "_id": "52dd2bd2044bf96a12ed231e",     "name": "uk",     "id": 6,     "users": []   } ] 

then have backbone model , collection:

group = backbone.model.extend({         urlroot: 'groups',     });  groups = backbone.collection.extend({         url: 'groups',         model: group     }); 

and i'd create instance of collection this:

groups = new groups();  groups.fetch(); 

but error:

uncaught typeerror: property 'url' of object [object object] not function

try 1

javascript

var group = backbone.model.extend({}); var groups = backbone.collection.extend({     model: group,     url: "groups",     parse: function(data) {         return data;     } }); var groupview = backbone.view.extend({     el: $("#page"),     initialize: function() {     },     render: function() {         var = this;         this.collection = new groups();         this.collection.fetch({             type: "get",             contenttype: 'application/json',             datatype: "json",             success: function(collection, response) {                 var template = _.template(yourviewtemplate, {                     groups: that.collection.models                 });                 that.$el.html(template);             },             error: function(collection, response) {                 alert("error");             }         });      } }); 

html

<% _.each(groups, function(group) { %>    <%= group.get('_id') %>    <%= group.get('name') %>    <%= group.get('id') %> <% }); %> 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -