我用谷歌搜索并用谷歌搜索没有运气试图弄明白为什么我在我的backbone.js app中有这个:
<div id="114" number="R462134068" line_items="[object Object]" status="ready" customer_name="John Doe" confirmation_code="PIMMS43" total="3.8" created_at="Fri May 10 2013 08:26:18 GMT+0100 (BST)" class="order-card-container">...
...这通常表明我错过了一些明显的东西。任何想法??
这是我视图的开头(CoffeeScript):
class BehindTheBarApp.Views.OrderCardView extends Backbone.View
@LATE_ORDER_WATCHER_INTERVAL_MS: 1000
className: 'order-card-container'
template: JST["behind-the-bar-app/templates/order_card"]
initialize: (order) =>
@order = order
# ...
另一个视图中的行加载模型......
_handleOrderAdded: (order, orders) =>
orderCardView = new BehindTheBarApp.Views.OrderCardView(order)
newItems = orderCardView.render().$el
@$el.append( newItems )
.isotope( 'reloadItems' ).isotope({ sortBy: 'original-order' })
@_orderCardViews.push orderCardView
答案 0 :(得分:0)
好的,事实证明你需要将哈希传递给initialize
方法,而不仅仅是模型对象。它应该是......
initialize: (options) =>
@order = options.order
...和...
_handleOrderAdded: (order, orders) =>
orderCardView = new BehindTheBarApp.Views.OrderCardView({order: order})