Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught Error: A "url" property or function must be specified for a CollectionView

Tags:

backbone.js

I know this error has come up a few times, but I'm still not sure how to make this work appropriately..

My magic begins here :

    var list_edit_member_view = new app.views.ListMemberEdit({
      el: $("#enterprise_member_list_edit_container"),
      list_ids: list_ids
    });
    list_edit_member_view.render();

And this loads this View (ListMemberEdit.js) which has this in the render() :

this.list_edit_member_view = new app.views.CollectionView({
  el: $("#enterprise_member_list_edit_container"),
  collection: app.peers,
  list_item: app.views.ListMemberEditSelection, 
  list_item_options: {list_ids: this.options.list_ids} 
});

Which loads a CollectionView view that renders its list_item_options as model views.. It is within this file (ListMemberEditSelection.js), that when I perform this.destroy, it will return :

Uncaught Error: A "url" property or function must be specified

So this makes me think that the Model or the Model URL is not being defined.. I'm just not sure where to put this since it works very similar to my other partials that are doing roughly the same thing..

Any thoughts? My apologies for the vagueness. Let me know if there's anything else you would like to look at!

I'm curious if its possible to see where this URL attribute would be written within the Object Model or Collection itself.

like image 296
Trip Avatar asked Oct 16 '12 15:10

Trip


1 Answers

This is because destroy() function will call Backbone.sync to update the server too, not only your models in the frontend. http://backbonejs.org/#Model-destroy

So, if you're using REST to sync your data, you'll need to set a url property in your model so Backbone know where to send request:

Backbone.Model.extend({
    url: "http://myapi.com/"
})

To allow more flexibility, you can also set a urlRoot: http://backbonejs.org/#Model-urlRoot

like image 146
Simon Boudrias Avatar answered Oct 06 '22 15:10

Simon Boudrias