簡體   English   中英

Backbone.js:從視圖中的另一個方法調用方法?

[英]Backbone.js: call a method from another method within a view?

我在Backbone工作。 在View中工作,我想從另一個方法中調用一個方法。

events: {
  "click span": "updateURL",
  "click .tag": "clearTag"
},
updateURL: function() { 
   // do stuff
},
clearTag: function(e) {
  console.log(this);
  // this fails
  this.updateURL();
},

但是clearTag中的this似乎綁定了一個元素,並且沒有調用updateURL 有沒有辦法可以在clearTag調用updateURL

從關於視圖事件綁定的Backbone源:

// Callbacks will be bound to the view, with `this` set properly.
// Uses event delegation for efficiency.
// Omitting the selector binds the event to `this.el`.
// This only works for delegate-able events: not `focus`, `blur`, and
// not `change`, `submit`, and `reset` in Internet Explorer.

這里的背景應該是你的觀點,所以還有其他的東西正在發生。 你可以提供你的來源嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM