问题
I have a template taskList
that receives a list of tasks and an options hash as arguments like this:
{{> taskList tasks=taskHelper options=listOptions}}
In this case, the taskHelper
returns all existing tasks. Is it possible to pass arguments to the taskHelper
in this scenario? For example, if I want to show only done tasks in the template, I would like to do something like this:
{{> taskList tasks=taskHelper 'done' options=listOptions}}
That won't work because the template compiler doesn't treat 'done'
as argument for the helper but as a non-keyword argument for the template, resulting in this error message:
Can't have a non-keyword argument after a keyword argument
回答1:
meteor < 1.1.1
You can make it work without any changes to your helpers by doing this:
{{#with taskHelper 'done'}}
{{> taskList tasks=this options=listOptions}}
{{/with}}
meteor >= 1.1.1
Nested helper expressions should solve this problem:
{{> taskList tasks=(taskHelper 'done') options=listOptions}}
来源:https://stackoverflow.com/questions/31441032/using-helper-arguments-and-template-keyword-arguments-at-the-same-time