N
N
New York Knicks2016-01-10 12:48:53
JavaScript
New York Knicks, 2016-01-10 12:48:53

How in the backbone to know that the fetch of the model was successful (event)?

There is a note model and a to_paste collection.
It is necessary to make sure that after filling the note model, the filling of the to_paste collection begins, because in to_paste I want to pass some parameters from note.
How to define an event when fetch is successful?
Filling them one by one (note.fetch(); to_paste.fetch();) and using fields doesn't work due to asynchronous loading.
Below is the code, as I did (several attachments to success), but it doesn't work.

note.fetch({
  success: function (collection, note1) {
        var noteView = new Memo.Views.FullNote( {model: note}, {flag: 1 } );
        var to_paste = new Memo.Collections.NotebookList();	
        to_paste.fetch({  
             success: function (collection) {
          var notebooks_to_paste = new Memo.Views.NotebookListToDelete( {collection: to_paste} );
          var notebook_id = note.get("notebook_id");	
          $('.example').html(notebooks_to_paste.render().el);	
        }
      });
      $('.content').html(noteView.render().el);
    }
  });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2016-02-02
@amyalichkin

backbonejs.org/#Events-catalog
"sync" (model_or_collection, resp, options) - when the model or collection has been successfully synced to the server.
in your case, working with promises is better
if jQuery is connected, fetchreturnsjQuery.Deferred

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question