gpt4 book ai didi

javascript - 将参数传递给 handlebars helper

转载 作者:行者123 更新时间:2023-11-29 22:10:42 26 4
gpt4 key购买 nike

所以我有一个非常简单的 Handlebars 助手 -

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"'
)

我有这个 Handlebars 代码 -

<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)
}))

如何将选定的参数正确传递给我的助手?

最佳答案

您在 Handlebars each 循环中使用了 selected 变量,所以我想 selected 不在范围内。

关于javascript - 将参数传递给 handlebars helper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18197218/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com