我有以下消息骨干设置:
class InboxItemView extends Backbone.View
initialize: ->
@model.on('change', @render, @)
render: ->
@$el.html JST['buy/messages/templates/received_message'](@model.toJSON())
@
class InboxListView extends Backbone.View
items: []
initialize: ->
@collection.on('reset', @reset, @)
reset: ->
_.each @items, (item) -> item.remove()
@items = _.map @collection.received(), (model) =>
item = new InboxItemView(model: model)
@$('tbody').append item.render().el
item
模型
class Message extends Backbone.Model
class Messages extends Backbone.Collection
model: Message
url: '/messages'
received: -> @filter (message) -> message.get('receiver').id == gon.userId
拉布尔:
object @message
attributes :id, :title, :body, :read_at, :created_at, :last_reply
node :path do |message|
message_path(message)
end
child :sender => :sender do
attributes :id, :nickname
end
child :receiver => :receiver do
attributes :id, :nickname
end
在初始渲染期间,一切都正确显示。但是,当我更改模型并且重新呈现列表项时,模型的发件人哈希变为空。因此渲染不会打印出发送者的名字。属性喜欢标题仍然显示,因为它们不是嵌套的。
为什么嵌套属性会消失?我在渲染一些中间模型吗?