我有一個Rails項目,其中包含Backbone.js和HAML作爲客戶端模板語言。Backbone.js Collection.models不能正常工作
在文件app /資產/視圖/ meeting.coffee:
class window.MeetingIndex extends Backbone.View
template: JST['meeting/index']
render: ->
@collection.fetch()
@$el.html(@template(collection: @collection))
this
在文件app /資產/ Java腳本/模板/會議
/index.hamlc
- console.log(@collection.length) # prints 0 in console
- console.log(@collection.models) # prints [] in console
- console.log(@collection.at(0)) # prints undefined in console
- window.x = @collection
如果我去了瀏覽器控制檯,我得到:
x.length # returns 2
x.models # returns [Meeting, Meeting]
x.at(0) # returns Meeting object
如果我能訪問.hamlc文件@collection變量,因爲我是在分配給獲勝dow.x.爲什麼我無法從.hamlc文件訪問@collection項目?
我需要這樣的東西
- for model in @collection.models
%p= model.get('landlord_id')
%p= model.get('tenant_id')
%p= model.get('at')
工作