edit
i put console.log in fetch success callback of home view (#/). these cid ids of fetches each time page loaded. can see end there 6 fetch requests being made when on original page load there one.
/#: c2 /#link1 + button: c4, c2 /#link1 + button: c4, c2, c2, c2 /#link2 + button: c4, c2, c2, c2, c2, c2 original
i'm experiencing odd bug in backbone button causing ajax requests duplicate. if go #/ click on #/link both of make ajax requests fine. problem when hit button go #/. makes normal ajax requests twice. if repeat process each time hit button increased number of duplicate requests (1 original + number of buttons): 2 button pushes = 3 ajax requests, 3 button pushes = 4 ajax requests
even when go different link (after i've used button) on view duplicates view's ajax requests. if click links , don't use button, bug never happens.
i'm using appview in router clean old view , load new view. calls backbone.view.prototype.close in turns calls view.close. think sound wanted include in case.
has experienced before?
appview
function appview () { this.view = null; this.showview = function (view, renderopts) { renderopts = (typeof renderopts === 'undefined') ? {} : renderopts; if (this.view) this.view.close(); this.view = view; $('.view').html(this.view.render(renderopts).el); } } backbone.view.prototype.close
backbone.view.prototype.close = function () { this.remove(); this.unbind(); if (this.onclose) this.onclose(); }; router
var router = backbone.router.extend({ routes: { '': 'home', 'compound_interests/new': 'editcompoundinterest', 'compound_interests/:id': 'viewcompoundinterest', 'compound_interests/:id/parameters': 'compoundinterestparameterseditor', 'compound_interests/:id/test': 'compoundinteresttester', 'compound_interests/:id/stream': 'compoundintereststreamer' }, initialize: function (opts) { this.appview = opts.appview; }, home: function () { var view = new homeview(); this.appview.showview(view); }, editcompoundinterest: function () { var view = new editcompoundinterestview(); this.appview.showview(view); }, viewcompoundinterest: function (id) { var view = new viewcompoundinterestview({ id: id }); this.appview.showview(view); }, compoundinterestparameterseditor: function (id) { var view = new compoundinterestparameterseditorview({ id: id }); this.appview.showview(view); }, compoundinteresttester: function (id) { var view = new compoundinteresttesterview({ id: id }); this.appview.showview(view); }, compoundintereststreamer: function (id) { var view = new compoundintereststreamerview({ id: id }); this.appview.showview(view); } }); router = new router({ appview: new appview() }); home view
var backbone = require('backbone'), _ = require('lodash'); var compoundinterests = require('../collections/compound_interests'); module.exports = backbone.view.extend({ initialize: function () { var = this; _.bindall(this, 'render'); this.template = jst['templates/home']; this.context = { data: {} }; this.compoundinterests = new compoundinterests(); this.compoundinterests.on('sync', this.render); this.compoundinterests.fetch(); }, onclose: function () { this.compoundinterests.off('sync'); this.render(); }, render: function () { this.context.data.compoundinterests = _.clone(this.compoundinterests.models); this.$el.html(this.template(this.context)); return this; } });
Comments
Post a Comment