【发布时间】:2015-04-28 14:32:03
【问题描述】:
已经提出(并回答)了一个类似的问题,但没有关于如何解决它的答案/解决方案
我正在为我的 Phonegap 项目使用 jQuery Mobile / Handlebars。到目前为止,一切似乎都运行良好。但是突然间我得到了这个奇怪的换行符:
"​ "
我使用以下代码制作列表:
// HTML
<ul id="guideListView" data-role="listview" ></ul>
<script id="guideListTemplate" type="text/x-handlebars-template">
{{#if this}}
{{#each this}}
<li class="guide">
<a href="{{guideUrl}}{{id}}" data-transition="slide" class="ui-nodisc-icon" >
<div class="name">{{name}}</div>
<div class="num-stores-container no-bold small">Stores: <span class="num-stores">{{storesCount}}</span></div>
</a>
</li>
{{/each}}
{{else}}
<li class="ui-btn">Sorry, no guides for <span class="city"></span></li>
{{/if}}
</script>
// JS
var template = Handlebars.compile($("#guideListTemplate").html());
$('#guideListView').append(template(guides));
$('#guideListView').listview().listview('refresh');
有人知道是什么原因造成的吗?
更新
我试过使用("#guideListTemplate").html().trim() 和$('#guideListView').html(template(guides));,但这并没有什么区别。这在 jQuery Mobile 中会很重要吗?
再调试一下,看来问题可能出在:
<script id="guideListTemplate" type="text/x-handlebars-template">
【问题讨论】:
-
嗯...好的,但是我该如何解决呢?
-
它可以在 html 中,也可以在
li元素中的变量之一中。用另一个编辑器检查它是否在 html 中,或者尝试输出你的变量。 -
我正在使用 PHP Storm 和我使用的代码,正如您在上面看到的那样。它只发生在 UL 和第一个元素之间。 (我会更新我的照片)
-
那么由于 li 的一个变量,它可能被插入到你的一些
li之前(这里是第一个和中间的一个)
标签: jquery jquery-mobile handlebars.js