【问题标题】:pass an argument type object in an iterate function (each) with handlears在带有句柄的迭代函数(每个)中传递参数类型对象
【发布时间】:2016-06-03 16:20:26
【问题描述】:

我想将一个对象作为参数传递给一个函数,该函数存在于一个使用把手的每个函数中,但是传递的对象在循环函数中是未定义的,而在“每个”之外一切都很好

{{#each sits}}
<tr>
      <td class="content content-center">{{@key}}</td>
      <td class="content ar">{{getMaxFormula terms sits 'd' sits.name}}</td>
</tr>
{{\each}}

在我的 json 文件中:

{
"terms": [
  {
     "evt": "d",
     "cap": 50000,
     "type": "d"
  }
  ],
"sits": {
  "2015": {
     "d": 50000,
     "i": 0,
     "a": 0,
     "cumul": 3491.637,
     "premium": 5000,
     "com": -1500,
     "term": -77.151,
     "taxEco": 1500
  },
  "2016": {
     "d": 46508.363,
     "i": 0,
     "a": 0,
     "cumul": 9131.576,
     "premium": 6000,
     "com": -550,
     "term": -89.622,
     "taxEco": 1800
  }
 }
}

【问题讨论】:

    标签: javascript json node.js handlebars.js each


    【解决方案1】:
    {{#each sits as |value key|}}
        <tr>
          <td class="content content-center">{{key}}</td>
        </tr>
    {{/each}}
    

    但是这里的sits.name 是什么:

    <td class="content ar">{{getMaxFormula terms sits 'd' sits.name}}</td>
    

    【讨论】:

    • 对不起,我错了,是sits.term,在getMaxFormula函数中出现问题,key的显示是alrigth
    猜你喜欢
    • 2013-06-04
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多