JavaUser JavaUser - 4 months ago 41
jQuery Question

mustache js syntax to call a function with parameter?

I am using Mustache.js to create a template html and show set of tables.
I want to call a function inside this template with a parameter.

Every table generated from through mustache template is having a button on top of it.
I want to write a onclick function for this button.So I need the table name when processing the event.

Can someone give me the correct syntax to pass parameter?

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


Thanks.

Answer

You are doing it almost right. Just add the quotes.

onclick="editTable('{{tableName}}')"