0

我想我在这里遗漏了一些非常基本的东西。我只想从咖啡脚本中的函数中获取值。我正在为那个值做console.log..

class App.Views.PlotModal extends Backbone.ModalView
  template: JST['plots/plot_modal'],

  render: ->
    console.log(@getSize.w);
    $(@el).html(@template(plot: @model));
    this.showModal();

  getSize: ->
    cell_div = document.getElementById("bgr");
    w : cell_div.offsetWidth * 3;
    h : cell_div.offsetHeight * 2;

当我在萤火虫中进入控制台时,我一直不确定。如果我只记录@getSize,我会恢复该功能。如何在这里返回变量 w 和 h?

在主干视图中执行这种操作(我想动态调整 iframe 的大小)也是一个好主意吗?

4

1 回答 1

0

在 CoffeeScript 中,这f将变量中的方法保留x为一个简单的函数:

x = @f

如果要调用该函数,则必须提供参数:

x = @f 'pancakes'

或添加括号:

x = @f()

所以你想要这个:

console.log(@getSize().w)

至于在 Backbone 中做这种事情,当然,为什么不呢?Backbone 倾向于将政策留给您。

于 2012-08-30T23:18:14.023 回答