src/components/collection_view.coffee in luca-0.9.1 vs src/components/collection_view.coffee in luca-0.9.2
- old
+ new
@@ -20,18 +20,21 @@
initialize: (@options={})->
_.extend(@, @options)
_.bindAll @, "refresh"
- unless @collection?
+ unless @collection? or @options.collection
throw "Collection Views must specify a collection"
unless @itemTemplate? || @itemRenderer? || @itemProperty?
throw "Collection Views must specify an item template or item renderer function"
Luca.components.Panel::initialize.apply(@, arguments)
+ if _.isString(@collection) and Luca.CollectionManager.get()
+ @collection = Luca.CollectionManager.get().get(@collection)
+
if Luca.isBackboneCollection(@collection)
@collection.bind "reset", @refresh
@collection.bind "add", @refresh
@collection.bind "remove", @refresh
@@ -44,10 +47,13 @@
if @itemRenderer? and _.isFunction( @itemRenderer )
content = @itemRenderer.call(@, item)
if @itemProperty
- content = if _.isFunction(@itemProperty) then @itemProperty() else (item.model.get(@itemProperty) || item.model[ @itemProperty ])
+ content = item.model.get(@itemProperty) || item.model[ @itemProperty ]
+ content = content() if _.isFunction(content)
+
+ content
makeItem: (model, index)->
item = if @prepareItem? then @prepareItem.call(@, model, index) else (model:model, index: index)
make(@itemTagName, @attributesForItem(item), @contentForItem(item))
\ No newline at end of file