【发布时间】:2012-08-02 11:04:05
【问题描述】:
我有以下代码
define [
"jquery",
"backbone",
"underscore",
"models/days"
], ($, Backbone, _, days) =>
class Calendar extends Backbone.View
el : "#calendar_box"
collection : days
display: =>
@collection.fetch_data
month :8
year :2012
, @render
render: =>
# console.log @collection - gives "undefined"
console.log @ # this returns "Window" instead of "Calendar" - current obj.
# return the calendar object
new Calendar()
这是 Coffeescript 中的 BackboneView,它请求服务器获取给定月份和年份的日期作为日历。
数据返回正常,因为我可以在 Chrome 控制台中检查它 - GET 请求及其响应。
但是,在“render”函数中,“@”看起来是在全局级别,而不是在“Calendar”级别。
这里发生了什么?
【问题讨论】:
标签: jquery model-view-controller backbone.js coffeescript requirejs