Dust.js模板不符合条件存在(Dust.js Template Not Honoring Conditional Exists)

编程入门 行业动态 更新时间:2024-10-27 07:22:55
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中的所有条件UNLESS in exists I输出一个值在guaranteeHistory中...

模板(这是有效的):

{?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上的开发模式下复制此问题,它在那里正常工作。 有人可以根据提供的信息帮助或告诉我可能出现的问题吗?

I am running into an interesting issue where my Dust.js template is not honoring an exists conditional.

My data looks like this:

{"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 } ], }

Template (Doesn't work):

{?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}

The issue is that no matter what happens, the template will only display everything in the else conditional UNLESS inside the exists I output a value inside guaranteedHistory...

Template (This works):

{?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}

I was not able to find any way to get around this. I also could not duplicate this issue within a dev mode on dustjs.com, it works correctly there. Could anyone please help or tell me what could possibly be going wrong based on the provided information?

最满意答案

没有理由认为这不应该像你所描述的那样正常工作。 另外,你提供的编译body_0肯定是正确的。

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

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

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

Dust 2.7.2 无法解决存在块中的Promise,因此这可能就是您要击中的内容。 如果需要,可以使用后备箱尖端,直到释放2.8。

There is no reason that this shouldn't work correctly as you've described it. In addition, the compiled body_0 you provided is definitely correct.

So, if this really is happening, the only possible reasons are:

You aren't rendering the template you think you are. This seems unlikely if you're compiling and rendering yourself. The value of guaranteedHistory isn't what you think it is. Because you are testing your template on http://www.dustjs.com/test/test.html and it works properly there, this is my guess.

So, this suggests to me that you have a race condition, and that you're trying to render with guaranteedHistory before it has been set (via some callback, Promise, etc).

Dust 2.7.2 doesn't resolve Promises in exists blocks so this may be what you're hitting. You can use the trunk tip if you need to until 2.8 is released.

更多推荐

本文发布于:2023-07-19 16:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1183586.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不符合   模板   条件   js   Dust

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!