javascript - Backbone: Navigate function not working -
so reason navigate won't work in 1 of views. i'm doing in 1 file now, may problem. know code horrible, i'm messing around backbone right now.
edit: put console.log()
in marketingpage's function route
, never gets called, there must wrong view.
also, error i'm getting chrome dev tools:
error in event handler 'undefined': indexsizeerror: dom exception 1 error: index or size negative, or greater allowed value. @ p (chrome-extension://mgijmajocgfcbeboacabfgobmjgjcoja/content_js_min.js:16:142) @ null.<anonymous> (chrome-extension://mgijmajocgfcbeboacabfgobmjgjcoja/content_js_min.js:18:417) @ chrome-extension://mgijmajocgfcbeboacabfgobmjgjcoja/content_js_min.js:1:182 @ miscellaneous_bindings:288:9 @ chrome.event.dispatchtolistener (event_bindings:390:21) @ chrome.event.dispatch_ (event_bindings:376:27) @ chrome.event.dispatch (event_bindings:396:17) @ object.chromehidden.port.dispatchonmessage (miscellaneous_bindings:254:22)
here's code:
/*global public, $*/ window.public = { models: {}, collections: {}, views: {}, routers: { }, init: function () { console.log('hello backbone!'); } }; var app = backbone.router.extend({ routes: { '': 'index', 'register': 'route_register', }, index: function(){ var marketing_page = new marketingpage(); }, route_register: function(){ var register_view = new registerview(); } }); window.app = new app(); var user = backbone.model.extend({ url: '/user', defaults: { email: '', password: '' } }); var marketingpage = backbone.view.extend({ initialize: function(){ this.render(); }, render: function(){ var template = _.template($("#marketing-page").html()); $('.search-box').after(template); }, events: { 'dblclick': 'route' }, route: function(e){ e.preventdefault(); console.log("in route"); window.app.navigate('register', {trigger: true}); this.remove(); } }); var registerview = backbone.view.extend({ initialize: function() { this.render(); }, render: function(){ var template = _.template($("#register-template").html()); $('.search-box').after(template); } }); $(document).ready(function () { backbone.history.start(); });
when type host/#register
browser directly, register view gets rendered, no matter click event won't seem work...
since handler function route
isn't being called, it's event delegation isn't working.
one thing note event handling set in backbone view scoped view's el
. don't see yours set explicitly, might creating empty div, handling events inside empty div (which don't want).
one trick use quick prototypes set view's el
jquery selector pointing exists on page already, in render
, show .show()
.
since you're not doing that, here's 1 thing try. we're doing setting $el
content , calling delegateevents
make sure events , handlers being bound.
var marketingpage = backbone.view.extend({ initialize: function(){ this.render(); }, render: function(){ this.$el.html(_.template($("#marketing-page").html())); $('.search-box').after(this.$el); this.delegateevents(); }, events: { 'dblclick': 'route' }, route: function(e){ e.preventdefault(); console.log("in route"); window.app.navigate('register', {trigger: true}); this.remove(); } });
Comments
Post a Comment