简体   繁体   English

检查骨干网中$(this.el)的值

[英]check value of $(this.el) in backbone

I'm just getting started with backbone, javascript, jquery and the like. 我刚刚开始了解骨干,javascript,jquery等。 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. 我正在看这篇文章的骨干视图Backbone.js View无法正确取消绑定事件 ,似乎我需要取消删除事件。 My event is tied to an element with id #createBtn. 我的事件与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. 我猜我的取消委托无法正常工作,并且想要一种调查$(this.el)实际指向的方式。 The whole JS this and everything is still confusing to me. 整个JS this ,一切仍然让我感到困惑。 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. 所以我不确定$(this.el)是否可以在我尝试的方法中工作,或者我是否需要做其他事情。 Any debugging hints of how $(this.el) is treated, or how I can look at that object would be super helpful. 有关如何对待$(this.el)或我如何查看该对象的任何调试提示都将非常有帮助。 Thanks! 谢谢!

Try console.log to output the value of this and this.el right before your undelegate. 在撤消删除之前,请尝试使用console.log输出this和this.el的值。 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. Chrome浏览器具有一些出色的调试工具。 You can step over jscript and get the contextual information. 您可以跳过jscript并获取上下文信息。 Ctrl + Shift + j. Ctrl + Shift + j。 Sources. 资料来源。 Add break point and control using step / skip buttons on the right. 使用右侧的“步骤/跳过”按钮添加断点并进行控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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