简体   繁体   中英

check value of $(this.el) in backbone

I'm just getting started with backbone, javascript, jquery and the like. I'm looking at a backbone view that from this post, Backbone.js View can't unbind events properly , it seems like I need to undelegate my event. My event is tied to an element with id #createBtn. So I tried this:

$(this.el).undelegate('#createBtn', 'click');

When my backbone view gets initialized, this event gets registered with:

events: {
            "click #createBtn": "createNewTemplate",

I still see my button doing its normal thing. I am guessing my undelegate is not working somehow and wanted a way to investigate what $(this.el) is really pointing at. The whole JS this and everything is still confusing to me. So I'm not sure if $(this.el) will even work in the method I am trying to, or if I need to be doing something else. Any debugging hints of how $(this.el) is treated, or how I can look at that object would be super helpful. Thanks!

Try console.log to output the value of this and this.el right before your undelegate. Like this...

console.log("this is this", this)

console.log("this is this.el", this.el)

Then look at the output in the console of the browser.

Chrome has some excellent debugging tools. You can step over jscript and get the contextual information. Ctrl + Shift + j. Sources. Add break point and control using step / skip buttons on the right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM