简体   繁体   English

在车把助手中使用变量

[英]using variables inside handlebars helper

I have a handlebars helper that compares two values. 我有一个比较两个值的车把帮手。 My code is below 我的代码如下

{{#compare action "blank" operator="!="}}
<button type="button" class="btn btn-primary btn-xs btn-approval" data-id="{{../sid}}" data-table="distributor">Approve</button>
<button type="button" class="btn btn-danger btn-xs btn-delete-approval" data-id="{{../sid}}" data-table="distributor">Delete</button>
{{/compare}}

for some reason I can't access the sid variable inside the helper. 由于某种原因,我无法访问帮助器内的sid变量。 How would I do that? 我该怎么办?

Pass sid it as parameter to helper. sid作为参数传递给助手。 And you can access it as an argument in helper function. 您可以在辅助函数中将其作为参数访问。

{{#compare ../sid  action "blank" operator="!="}}
      <button type="button" class="btn btn-primary btn-xs btn-approval" data-id="{{sid}}" data-table="distributor">Approve</button>
      <button type="button" class="btn btn-danger btn-xs btn-delete-approval" data-id="{{sid}}" data-table="distributor">Delete</button>
{{/compare}}

The helper function can then access it as an argument. 然后,辅助函数可以将其作为参数进行访问。

Handlebars.registerHelper('compare', function(sid, action, blank, operator, options) {
    this.sid = sid;
    // your code here...
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM