Kev*_*ary 4 javascript asp.net-mvc jquery json dust.js
我正在使用jQuery 1.8.2和Dust.js v1.1.1在JavaScript应用程序中进行MVC风格的模板化.当我使用{@gt}逻辑助手时,我收到以下控制台错误:
Uncaught TypeError: Cannot read property 'gt' of undefined
Run Code Online (Sandbox Code Playgroud)
我相信我的模板中使用了正确的语法:
<ul class="listview">
{#seasons}
<li>
<h3>{name}</h3>
<p class="desc">{id}</p>
{@gt key="months" value="0"}
<span class="count">{months}</span>
{/gt}
</li>
{/seasons}
</ul><!--// end .listview -->
Run Code Online (Sandbox Code Playgroud)
这是JSON结构:
{
"seasons":[
{
"name":"Spring",
"id":"weklv7",
"months": 8
},
{
"name":"Summer",
"id":"lvuec5",
"months": 4
}
]
}
Run Code Online (Sandbox Code Playgroud)
如果我{@gt}从模板中删除逻辑助手,则错误消失,模板作为HTML正确加载.例如:
<ul class="listview">
{#seasons}
<li>
<h3>{name}</h3>
<p class="desc">{id}</p>
<span class="count">{months}</span>
</li>
{/seasons}
</ul><!--// end .listview -->
Run Code Online (Sandbox Code Playgroud)
非常感谢任何帮助,谢谢!
非常密切关注提供的链接smfoote.
为了在节点中"加载"防尘助手,您需要的特定语法是:
var dust = require('dustjs-linkedin');
dust.helper = require('dustjs-helpers');
Run Code Online (Sandbox Code Playgroud)
请注意,这不是在链接上写的内容,链接文件应该是dust.helper(S)和's'.
您根本无法在主文档站点的任何位置找到该短语.
显然,这应该是事物应该连接的方式.
有时我觉得那些未能记录他们对项目所做的重大改变的影响的人正在偷走我的生命.这个特殊的文档差距大约5个小时.
为了帮助那些同时运行npm的灵魂安装dustjs-linkedin和npm安装dustjs-helpers并且想知道为什么这不仅仅是自动工作(因为它基本上是网站上的所有文档所暗示的).我将重建您在此处收到此错误时通常会遇到的错误:
if( dust.helpers[name]){
^
Run Code Online (Sandbox Code Playgroud)
然后其中一个..
TypeError: Cannot read property 'if' of undefined
TypeError: Cannot read property 'math' of undefined
TypeError: Cannot read property 'eq' of undefined
TypeError: Cannot read property 'not eq' of undefined
TypeError: Cannot read property 'ne' of undefined
TypeError: Cannot read property 'lt' of undefined
TypeError: Cannot read property 'gt' of undefined
TypeError: Cannot read property 'select' of undefined
TypeError: Cannot read property 'size' of undefined
TypeError: Cannot read property 'tap' of undefined
TypeError: Cannot read property 'contextDump' of undefined
TypeError: Cannot read property 'idx' of undefined
TypeError: Cannot read property 'sep' of undefined
Run Code Online (Sandbox Code Playgroud)
有趣的是,如果你将dustjs-helpers分配给"helper"而不是"helper",你会得到一个不同的错误:
undefined:1
").write("</form>").write("\n\n").helper("contextDump",ctx,{},null).write("\n\
^
TypeError: Cannot call method 'write' of undefined
Run Code Online (Sandbox Code Playgroud)
编写一些代码来检测某人是否正在尝试使用以"@"开头的内容并说...嘿,你可能没有加载到你的帮助程序库中...并使它在节点中工作而不是 - 它是相当简单的节点上下文...或者他们可以修复文档.
我真诚的希望,我花了额外的15分钟来解决一个谷歌可能会让Grok在我失去的5个小时内拯救其他人的答案.
-ft
听起来你的问题是dust.helpers不存在,可能是因为它是从Dust核心中删除的.确保在模板呈现的任何位置都加载了Dust core和Dust helper.
| 归档时间: |
|
| 查看次数: |
6469 次 |
| 最近记录: |