You could pass more than 1 variable to your template, the first being your model and the second being the attributes of primaryData.
Can't access model attributes from Backbone View
-
04-07-2023 - |
题
I'm walking into a large Backbone.js
project so I'm still getting my bearings. My template, my-group-item.jhbs
has:
{{#if isComplete}}
.row-fluid
.span2
img.entity-image(src="/pictures/{{entityId}}.png")
.span10
.row-fluid
.span12
h3 {{entityName}}
p My first variable {{totalFirst}} and my second variable {{totalValue}}
{{/if}}
My View
is:
module.exports = class MyItemView extends View
className: ->
templateData = @getTemplateData()
primaryData = @model.get('primaryData')
tagName: 'li'
template: require 'views/my-group-item'
initialize: () ->
super
primaryData = @model.get('primaryData')
In my template, the totalFirst
and totalValue
variables show nothing.
I'm calling my view with:
@groupView = new MyItemView
collection: groups
el: '.group-list'
How can I get these to show in the template?
解决方案
不隶属于 StackOverflow