If statement 手柄:使用IF语句显示不同的HTML标记
部分:If statement 手柄:使用IF语句显示不同的HTML标记,if-statement,compiler-errors,handlebars.js,If Statement,Compiler Errors,Handlebars.js,部分: <h2>{{regionName}}</h2> {{~#if @root.config.isMobile}}<ul>{{else}}<div>{{/if~}} {{~#each stores~}} {{~#if @root.config.isMobile}}<li>{{/if~}} {{> address-partial }} {{~#if @root.config
<h2>{{regionName}}</h2>
{{~#if @root.config.isMobile}}<ul>{{else}}<div>{{/if~}}
{{~#each stores~}}
{{~#if @root.config.isMobile}}<li>{{/if~}}
{{> address-partial }}
{{~#if @root.config.isMobile}}</li>{{/if~}}
{{~/each~}}
{{~#if @root.config.isMobile}}</ul>{{else}}</div>{{/if~}}
从第一行和最后一行中删除平铺后——同样的错误
从代码中删除所有波浪形块后--出现相同的错误
删除除第一行和最后一行以外的所有内容后--新错误:
Error: Unable to find closingTag after {"name":"openingTag","value":"ul"}. (token: 26)
at findClosingTokenInner (filename:3600:8)
at findClosingToken (filename:3635:16)
这非常有效:
{{~#if @root.config.isMobile~}}
<h2>{{regionName}}</h2>
<ul>
{{~#each stores~}}
<li>
{{> address-partial }}
</li>
{{~/each~}}
</ul>
{{~else~}}
<h2>{{regionName}}</h2>
<div>
{{~#each stores~}}
{{> address-partial }}
{{~/each~}}
</div>
{{~/if~}}
{{{#if@root.config.isMobile}
{{regionName}}
{{{#每个存储}
-
{{>地址部分}
{{~/每个}}
{{~else~}
{{regionName}}
{{{#每个存储}
{{>地址部分}
{{~/每个}}
{{{/if}}
你可以看到,这是多久,现在,我重复几乎所有的信息。是否没有办法让原始代码与把手一起工作,或者我遗漏了什么(可能真的很简单
另外,如果你能解释为什么这个问题是一件事,我将永远感激你
谢谢你 下面是您的方法的测试片段,同样的方法没有~。所有这些都在工作,我没有做任何修改,除了删除方法3和4上的~。尝试使用新版本的把手
$(文档).ready(函数(){
变量上下文={
“config”:{“isMobile”:true},
“regionName”:“Region1”,
“店铺”:[
{“名称”:“存储1”,“地址”:“地址1”},
{“名称”:“存储2”,“地址”:“地址2”},
{“名称”:“存储3”,“地址”:“地址3”}
]
};
var source=$(“#sourceTemplate”).html();
var template=handlebar.compile(源代码);
var html=模板(上下文);
$(“#resultPlaceholder”).html(html);
});代码>
{{{#*内联“地址部分”}
{{name}}-{{address}
{{/inline}
方法1:~+compact
{{regionName}}
{{{{#if@root.config.isMobile}}{{else}{{/if}}
{{{#每个存储}
{{{{#if@root.config.isMobile}- {{/if}
{{>地址部分}
{{{#if@root.config.isMobile}
{{/if}
{{~/每个}}
{{{{#if@root.config.isMobile}}
{{else}}{{/if}}
方法2:长+~
{{{#if@root.config.isMobile}
{{regionName}}
{{{#每个存储}
-
{{>地址部分}
{{~/每个}}
{{~else~}
{{regionName}}
{{{#每个存储}
{{>地址部分}
{{~/每个}}
{{{/if}}
方法三:no~+long
{{{#if@root.config.isMobile}
{{regionName}}
{{{#每个商店}
-
{{>地址部分}
{{/每个}}
{{else}
{{regionName}}
{{{#每个商店}
{{>地址部分}
{{/每个}}
{{/if}
方法4:no~+紧致法
{{regionName}}
{{{if@root.config.isMobile}}{{else}{{/if}}
{{{#每个商店}
{{{#if@root.config.isMobile}- {{/if}
{{>地址部分}
{{{#if@root.config.isMobile}
{{/if}}
{{/每个}}
{{{if@root.config.isMobile}}
{{else}}{{/if}}
不应是
的子女。UL和OL只能包含混合的
元素、
元素和
元素。@chharvey,这完全不是重点,但感谢您指出。已修复。我已将您的代码复制粘贴到选择了v4.0.3的版本中,并且运行时没有任何编译错误。
{{~#if @root.config.isMobile~}}
<h2>{{regionName}}</h2>
<ul>
{{~#each stores~}}
<li>
{{> address-partial }}
</li>
{{~/each~}}
</ul>
{{~else~}}
<h2>{{regionName}}</h2>
<div>
{{~#each stores~}}
{{> address-partial }}
{{~/each~}}
</div>
{{~/if~}}