Ste*_*ven 7 jquery jquery-mobile handlebars.js
一个类似的问题已被提出(并回答),但没有答案/解决方案如何解决它
我正在为我的Phonegap项目使用jQuery Mobile/Handlebars.到目前为止,一切似乎都很好.但突然间我得到了这个奇怪的换行符:
"​ "
Run Code Online (Sandbox Code Playgroud)

我使用以下代码来制作列表:
// 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');
Run Code Online (Sandbox Code Playgroud)
有谁知道这可能导致什么?
更新
我尝试使用("#guideListTemplate").html().trim()和$('#guideListView').html(template(guides));,但这没有任何区别.这可能是jQuery Mobile的一大特色吗?
多一点调试,似乎问题可能在于:
<script id="guideListTemplate" type="text/x-handlebars-template">?
Run Code Online (Sandbox Code Playgroud)
好的,所以我从这个帖子中找到了一个解决方案.
问题是当你尝试获取javascript字符串的html时,你可能会得到zero width space.
Unicode具有以下零宽度字符:
所以要通过使用正则表达式删除unicode charecter来解决我的问题:
var source = $("#guideListTemplate").html().replace(/[\u200B]/g, '');
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题并找到了解决方案.问题源于我们将片段从www复制粘贴到我们的编辑器中,有时会导致像space被复制为数字实体一样的字符.编辑器解析实体,所以一切看起来都很普通.解决方案是找到一种方法来突出显示数字实体(如果它没有在编辑器中内置,查找扩展名)并删除它.正则表达式/替换不是一个解决方案.
| 归档时间: |
|
| 查看次数: |
4636 次 |
| 最近记录: |