【发布时间】:2015-05-23 01:22:12
【问题描述】:
我有一个包含这两个函数的集合:
class SomeCollection
handleData: (data) ->
console.log JSON.stringify(data)
return data
getData: ->
Session.ajax
url: "/some/endpoint/"
type: ‘get'
然后我有视图调用集合中的函数以返回该会话数据:
class SomeView
initialize: =>
@listenTo @collection
my_session_data = @collection.getData().done @collection.handleData
renderTable: =>
@$el.html @template
my_session_data: my_session_data
console.log JSON.stringify(my_session_data)
根据控制台结果,handleData() 中的 console.log 数据似乎正确显示。但是当从 renderTable() 调用 console.log 时,它会在控制台中返回“未定义”。
如何从视图中获取 renderTable() 以返回在 handleData() 中似乎正常工作/出现的数据?
【问题讨论】:
标签: javascript ajax backbone.js coffeescript