Dust.js 模板不符合条件存在

Dust.js Template Not Honoring Conditional Exists

我 运行 遇到了一个有趣的问题,我的 Dust.js 模板没有遵守存在条件。

我的数据是这样的:

{"guaranteedHistory": [
    {
      "depositDate": "2017-08-31T00:00:00.000-0500",
      "interestRate": 515.5,
      "maturityDate": "2017-08-31T00:00:00.000-0500",
      "beginningBalance": 874757257.4,
      "deposits": 4.25,
      "transferIn": 75.7,
      "investmentReturn": 52.71,
      "amtReinvested": 5.5,
      "maturityWithdrawal": 6.66,
      "surrenderCharge": 7.77,
      "endingBalance": 8.88,
      "surrenderValue": 5735.56
    }
  ],
}

模板(无效):

{?guaranteedHistory}
  <table id="a">
    <thead>
      <tr>
        <th>&nbsp;</th>
        <th>What happened this period</th>
        <th></th>
      </tr>
    </thead>
  </table>
{:else}
  <table id="b">
    <thead>
      <tr>
        <th>Deposits</th>
        <th>Dividends</th>
        <th>Investment return</th>
      </tr>
    </thead>
  </table>
{/guaranteedHistory}

问题是,无论发生什么,模板都只会显示 else 条件中的所有内容,除非在 exists 中,我在 guaranteedHistory 中输出一个值...

模板(有效):

{?guaranteedHistory}
  {guaranteedHistory[0].depositDate}
  <table id="a">
    <thead>
      <tr>
        <th>&nbsp;</th>
        <th>What happened this period</th>
        <th></th>
      </tr>
    </thead>
  </table>
{:else}
  <table id="b">
    <thead>
      <tr>
        <th>Deposits</th>
        <th>Dividends</th>
        <th>Investment return</th>
      </tr>
    </thead>
  </table>
{/guaranteedHistory}

我找不到任何方法来解决这个问题。我也无法在 dustjs.com 的开发模式中重现此问题,它在那里可以正常工作。任何人都可以根据提供的信息帮助或告诉我可能出了什么问题吗?

没有理由不能像您描述的那样正常工作。另外,你提供的编译的body_0肯定是正确的

所以,如果这真的发生了,唯一可能的原因是:

  1. 您没有呈现您认为的模板。如果您自己编译和渲染,这似乎不太可能。
  2. guaranteedHistory 的值不是你想的那样。因为您正在 http://www.dustjs.com/test/test.html 上测试您的模板并且它在那里正常工作,所以这是我的猜测。

所以,这向我表明你有竞争条件,并且你试图在 guaranteedHistory 设置之前(通过一些回调、Promise 等)进行渲染。

Dust 2.7.2 doesn't resolve Promises in exists blocks 所以这可能就是你要打的。如果需要,您可以使用 trunk tip,直到 2.8 发布。