流星车把模板如何评估参数 [英] Meteor handlebars template how to eval parameters

查看:99
本文介绍了流星车把模板如何评估参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < template name =participant> 
< div class =animated fadeIn>
< a href ={{pathFor'participants'}}>←返回< / a>
{{#with参与者}}
< div class =参与者>
< h3> {{完整名称}}< / h3>
< dl>
< dt>电子邮件< / dt>
< dd> {{email}}< / dd>
< dt>手机< / dt>
< dd> {{tel}}< / dd>
< dt>城市< / dt>
< dd> {{zip}} {{city}}< / dd>
< dt>创建时间< / dt>
< dd>新增{{created_on}}< / dd>

< / dl>
{{> quickfield name =emailvalue = email}}
< p>& nbsp;< / p>
< h5>< a href =#class =delete>删除< / a>< / h5>
< / div>
{{/ with}}
< / div>
< / template>

其中,Quickfield模板为:

 < template name =quickfield> 
< input id ={{name}}value ={{value}}class =bound>
< / template>

我想在模板调用中跳过第二个名为value的参数,因为它与名称参数相同。我们应该只能用一个参数来构建模板。



理想情况下,我应该有这样的:

  {{> quickfield name =email}} 
< template name =quickfield>
< input id ={{name}}value ={{eval('this。'+ name)}}class =bound>
< / template>

但这不起作用。我能做什么?



Thks!

解决方案

帮助:

  UI.registerHelper('get',function(name){
return this [name];
});

现在您可以将模板重写为:

 < template name =quickfield> 
< input id ={{name}}value ={{get name}}class =bound>
< / template>


I have a participant being rendered in this template:

<template name="participant">
    <div class="animated fadeIn">
      <a href="{{pathFor 'participants'}}">← Back</a>
      {{#with participant}}
        <div class="participant">
          <h3>{{fullname}}</h3>
            <dl>
                <dt>E-mail</dt>
                <dd>{{email}}</dd>
                <dt>Phone</dt>
                <dd>{{tel}}</dd>
                <dt>City</dt>
                <dd>{{zip}} {{city}}</dd>
                <dt>Creation time</dt>
                <dd>added {{created_on}}</dd>

            </dl>
            {{>quickfield name="email" value=email}}
          <p>&nbsp;</p>
          <h5><a href="#" class="delete">Delete</a></h5>
        </div>
      {{/with}}
    </div>
</template>

Where Quickfield template is:

<template name="quickfield">
    <input id="{{name}}" value="{{value}}" class="bound">
</template>

I would like to skip the second parameter, called "value", in the template call, as it is the same as the name parameters. We should be able to build the template with only one parameter.

Ideally, I should have this:

{{>quickfield name="email"}}
<template name="quickfield">
    <input id="{{name}}" value="{{eval('this.' + name)}}" class="bound">
</template>

But that doesn't work. How can I do?

Thks!

解决方案

Create an additional helper:

UI.registerHelper('get', function(name) {
  return this[name];
});

Now you can rewrite your template as:

<template name="quickfield">
  <input id="{{name}}" value="{{get name}}" class="bound">
</template>

这篇关于流星车把模板如何评估参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆