javascript - Backbone running a method based on a collection listener -


in application have following code,

initialize: function() {     pops.collections.teamcollection = this.collection;     this.collection.fetch();      this.collection.on('sync', this.render, this); },  render: function() {     this.addall();     return this; }, 

its pretty self explanatory, fetch collection, once synced server run render collection. @ time of writing sequence of code seemed a idea looks when save model of collection runs sync listener , runs render again. not behaviour want. there listener can use listen initial fetch being complete?

according backbone documentation,

backbone.sync function backbone calls every time attempts read or save model server.

the event "catch-all" crud operations communicating server, why it's being fired on saving model. looking deeper documentation gives clues how .fetch() works

when model data returns server, uses set (intelligently) merge fetched models, unless pass {reset: true}, in case collection (efficiently) reset.

by revising call this.collection.fetch({reset: true}), collection load data , fire reset event can listened instead of sync. solve problem.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -