Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone.js add event problem
    primarykey
    data
    text
    <p>I have the following backbone.js code and i have a problem in that event before i fetch the "add" event is triggered from the collections. Adding <code>this.field.add(list_fields);</code> in the <code>success:</code> fetch has resulted in an error. How do i make sure the model is fetched then the add event is run after that</p> <pre><code>$(function() { $(".chzn-select").chosen(); /*********************************Models*************************************************/ var Table = Backbone.Model.extend({ urlRoot : '/campusfeed/index.php/welcome/generate' }); var Field = Backbone.Model.extend({ urlRoot: '/campusfeed/index.php/welcome/generate' }); /**************************Collections*************************************************/ Tables = Backbone.Collection.extend({ //This is our Friends collection and holds our Friend models initialize : function(models, options) { this.bind("add", options.view.addFriendLi); //Listen for new additions to the collection and call a view function if so } }); var Fields = Backbone.Collection.extend({ model:Field, url:'http://localhost/campusfeed/index.php/welcome/generateFields', initialize : function(models, options) { this.bind("add", options.view.getFields); } }); /************************************Views**************************************************/ var m="shit"; var app = Backbone.View.extend({ el:'body', initialize:function(model,options){ //Create collections in here this.table = new Tables(null,{ view : this }); this.field = new Fields(null,{ view : this }); }, events : { "click #choose" : "generate" }, generate:function(){ var table = ( this.$("#table option:selected").text()); var dbname = ( this.$("#database").text()); var list_fields = new Field(); list_fields.urlRoot = list_fields.urlRoot+"/"+dbname+"/"+table; list_fields.fetch({ success:function(){ console.log(JSON.stringify(list_fields)); } }); this.field.add(list_fields); }, getFields:function(model){ console.log(JSON.stringify(model)); } }); var apprun = new app; /* var data = new Fields(); data.url=data.url+"/some/data"; alert(data.url); data.fetch(); var staff = new Table(); staff.fetch(); var field = new Field();*/ }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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