所以我有一个非常简单的车把助手——
Handlebars.registerHelper('selectRow', (rowIndex, selectedIds) ->
console.log 'row index'
console.log rowIndex
console.log selectedIds
isSelected = _.indexOf(rowIndex, selectedIds)
if isSelected > -1
return 'class="row-selected"'
)
我有这个车把代码-
<div class="title">{{ title }}</div>
<hr/>
<table cellspacing="0" cellpadding="0">
<thead>
{{#each columns}}
<th class="col-heading" data-heading="{{ this }}">{{ this }}</th>
{{/each}}
</thead>
<tbody>
{{#each rows}}
<tr {{#selectRow @index selected }}>
{{#each this}}
<td>
{{this}}
</td>
{{/each}}
</tr>
{{/selectRow}}
{{/each}}
</tbody>
</table>
所选参数始终未定义。如果我在其他任何地方添加一个 {{ selected }} ,它会显示一个数组,正如您从下面看到的那样,它应该 -
data = @model.data()
selected = @model.get('selection').get('selected')
@$el.html(@tableContentsTemplate({
columns: @model.get('columns')
rows: data
title : @model.get('title')
selected: JSON.stringify(selected)
}))
如何将所选参数正确传递给我的助手?