我正在使用 Mustache.js 创建模板 html 并显示一组表格。 我想使用参数调用此模板内的函数。
通过 mustache 模板生成的每个表格顶部都有一个按钮。 我想为这个按钮写一个onclick函数。所以我在处理事件时需要表名。
谁能告诉我传递参数的正确语法?
<script id="TableTemplate" type="x-tmpl-mustache">
{{#tableDetails}}
<button type="button" id=Edit_{{tableName}} onclick="editTable({{tableName}})">
{{#tableDetails}}
</script>
function editTable(tableName){
console.log("tableName >>>"+tableName)
}
谢谢。
最佳答案
你做的几乎是对的。只需添加引号即可。
onclick="editTable('{{tableName}}')"
关于javascript - mustache js语法调用带参数的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38694678/