Handlebars.JS(w / Dashbars)解析错误“期望open_endblock得到反向” [英] Handlebars.JS (w/ Dashbars) parse error "expecting open_endblock got inverse"

查看:144
本文介绍了Handlebars.JS(w / Dashbars)解析错误“期望open_endblock得到反向”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我将转入Handlebars模板的输出转储并通过JSONlint.com运行并验证,因此我的输入有效。其次,这是我可以编写的最具代表性的示例代码,但不包含重要数据: http://codepen.io/Muzical84/pen/BNBLom?editors=101 (请注意,如果您有HTTPS-Everywhere,请在codepen.io中将其关闭,因为该支持被列为部分, Chrome可能仍然会吠叫不安全的脚本;除了jQuery之外,我还将其中的所有库都缩小了,放在JS部分的底部,以尽可能多地关闭开发工具。)我还将包括一些代码如下,因为SO告诉我,它不会让我包含该链接,否则。



无论如何,我正在尝试使用带有Dashbars边的Handlebars来输出ColdFusion WSDL的结果。它在星期五下午工作,但是当我上周一开始编写代码时,我做的所有事情都会产生这个错误:

 未捕获错误:第139行解析错误:
... {{else}}
----------------------- ^
期待'OPEN_ENDBLOCK',得到'INVERSE'

当时的代码是:

 < td>< p> {{#each phoneObj}} 
{{#if(s-start-与'Y'PRIMARY_FLAG)}}
< span class =primaryInformation> {{PHONE}}< / span>
< span class =lightBlue>
{{#if COMM_LOCATION_CODE}}
{{COMM_LOCATION_CODE}}
{{else}}
{{PHONE_TYPE}}
{{/ if}}
< / span>
{{else}}
{{PHONE}}
< span class =lightBlue>
{{#if COMM_LOCATION_CODE}}
{{COMM_LOCATION_CODE}}
{{else}}
{{PHONE_TYPE}}
{{/ if}}
< / span>
{{/ if}}
< br />
{{else}}
未找到电话或电子邮件数据
{{/每个}}< / p>
< / td>

(我为格式化道歉......)手机数据(实际上是手机和/或e -mail;我没有设计这个数据库......)大约是我的codepen.io示例中模板的两端之间的一半。 (整个事情真的很长,我不想浪费任何人的时间来处理整个冗长的事情。)最初,我做了更多 {{#if fieldThatShouldHaveData}} {{else}} 但出于调试目的。



起初,我已将该对象命名为phone,并认为可能phone.PHONE为太模糊了,但this.PHONE并将其重命名为phoneObj并没有改变任何内容。这些都在一个巨大的 {{#each this}} 中,用于打印表格的行。我没有使用任何标签,我没有事先在模板中使用过,而且我确实证实了嵌套if和等是合法的。



顺便说一句,即使我用 {{!如果xyz}} 我仍然得到相同的错误,引用相同的行。



我也遇到了我最外面的 {{#each}} 循环,只有最后一条返回的记录通过模板输出。在打开 {{#each}} 之后,所有内容都会登录 {{log this}} ,但它甚至没有隐藏在HTML输出中。



我对模板很陌生,所以之前做过这些的人可能会认为这是一个愚蠢的问题。我已经用可用的文档做了我能做的事情,但是大多数的handlebars官方文档似乎都假设您熟悉模板。

事实证明,错误消息引用的行是错误的(可能是因为,当我在我的代码文件中查找行号时,我忘记了添加从<$ c $头模板中的行c>< cfinclude> 在顶部。对于ColdFusion,我仍然是新的......发生这种情况......)再往下看,我缺少一个 {{/ if}} 我不确定为什么这些行被引用,但它是。然而,我的每个只打印最后一个项目的错误仍然存​​在,但我会为此创建一个不同的问题。


First, I dumped the output that's going to the Handlebars template and ran it through JSONlint.com and it validates, so my inputs are valid. Second, this is the best example code I could cook up that's representative but doesn't include vital data: http://codepen.io/Muzical84/pen/BNBLom?editors=101 (note, if you have HTTPS-Everywhere on, turn it off on codepen.io since the support is listed as "partial," and Chrome might still bark about unsafe scripts; I included all of the libraries besides jQuery, minified, in the bottom of the JS portion in order to shut up dev tools as much as I could.) I'll also be including some of the code below because SO is telling me that it won't let me include that link otherwise.

Anyway, I'm trying to use Handlebars with a side of Dashbars to output the results of a ColdFusion WSDL. It was working on a Friday afternoon, but then when I started working on code last Monday, everything I do yields this error:

     Uncaught Error: Parse error on line 139:
     ...                    {{else}}           
     -----------------------^
     Expecting 'OPEN_ENDBLOCK', got 'INVERSE'

The code at that point is:

<td><p>{{#each phoneObj}}
                    {{#if (s-start-with? 'Y' PRIMARY_FLAG)}}
                        <span class="primaryInformation">{{PHONE}}</span>
                            <span class="lightBlue">
                                {{#if COMM_LOCATION_CODE}}
                                    {{COMM_LOCATION_CODE}}
                                {{else}}
                                    {{PHONE_TYPE}}
                                {{/if}}
                            </span>
                    {{else}}
                        {{PHONE}}
                        <span class="lightBlue">
                            {{#if COMM_LOCATION_CODE}}
                                {{COMM_LOCATION_CODE}}
                            {{else}}
                                {{PHONE_TYPE}}
                            {{/if}}
                        </span>
                    {{/if}}
                    <br />
                {{else}}
                    No phone or e-mail data found
                {{/each}}</p>
            </td>

(I apologize for formatting...) The phone data (which is actually phone and/or e-mail; I didn't design this database...) is roughly half-way between the ends of the template that are in my codepen.io example. (The whole thing is really long and I didn't want to waste anyone's time with the whole, long thing.) Originally, I was doing more {{#if fieldThatShouldHaveData}} {{else}} but took that out for debugging purposes.

At first, I had named the object "phone" and thought that maybe "phone.PHONE" was too ambiguous, but "this.PHONE" and renaming it to phoneObj didn't change anything. This is all within a huge {{#each this}} that prints the rows of the table. I'm not using any tags that I don't use earlier in the template without incident, and I did confirm that it's legal for me to nest if's and etc.

Incidentally, even if I comment out those lines with {{! if xyz}} I still get the same error, citing the same line.

I'm also having the problem of my outermost {{#each}} looping in such a way that only the last record returned is being output through the template. Everything logs in {{log this}} after that opening {{#each}} , but it's not even hiding in the HTML output somewhere.

I AM new to templating, so those of you who've done it before may think this is a stupid question. I've done what I can with the documentation available, but much of the handlebars official documentation seems to presume familiarity with templating.

解决方案

It turned out that the line cited by the error message was wrong, (probably because, when I was looking for the line number in my my code file, I was forgetting to add the lines from the head template from my <cfinclude> at the top. I'm still new enough to ColdFusion that...that happens...) Further on down, I DID have a missing {{/if}} I'm not sure why the lines were being cited that were, but there it is. However, my "each only prints the last item" bug persists, but I'll create a different question for that.

这篇关于Handlebars.JS(w / Dashbars)解析错误“期望open_endblock得到反向”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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