我正在使用木偶来渲染我的视图和模板。
除了将集合传递给我的视图之外,我还需要在模板中显示其他自定义变量,例如“昵称”,如下所示
我目前只将一个集合传递给我的“message_view”。我如何也可以为“昵称”传递自定义变量?
//template JST["backbone/templates/messages/index"]
.message_wrapper
.title
//NEED TO DISPLAY NICKNAME here
%h4 Chat with <%= nickname %>
%ul.messages
%li.message.load_more_messages
视图和控制器设置如下:
List.Controller =
listMessages: (nickname) ->
messages = new Onethingaday.Collections.MessagesCollection()
messages.url = "/v1/messages/#{nickname}.json"
messages.remoteGet
success: (collection, response) =>
//ONLY PASSING IN COLLECTION TO MESSAGE VIEW, NEED VARIABLE NICKNAME AS WELL
messages_view = new List.Messages
collection: collection
@layout.messagesRegion.show(messages_view)
class List.Message extends Marionette.ItemView
template: JST["backbone/templates/messages/message"]
className: 'message'
tagName: 'li'
class List.Messages extends Marionette.CompositeView
template: JST["backbone/templates/messages/index"]
itemView: List.Message
itemViewContainer: "ul.messages"