0

我正在使用 JQuery Mobile 和 Mustache Templating 创建一个移动应用程序。但是我在创建 ul 列表时遇到了问题。

一个非常简单的例子就是这个。

     var html = '';
        html += '<ul data-role="listview" data-theme="g"><li><a href="acura.html">Acura</a></li><li><a href="audi.html">Audi</a></li><li><a href="bmw.html">BMW</a></li></ul>

$('#listpage #test_view').html(html).trigger('create');

我一次又一次遇到的问题是一个看起来像这样的错误:

Uncaught TypeError: Cannot read property 'jQuery171025502100912854075' of undefined

填充信息是这样的:

Uncaught TypeError: Cannot read property 'jQuery171025502100912854075' of undefined
$.widget._createSubPagesbase:5113
$.widget.refreshbase:4947
$.widget._createbase:4832
$.Widget._createWidgetbase:1065
$.widget._createWidgetbase:1182
$.widget.$.(anonymous function).(anonymous function)base:966
$.widget.bridge.$.fn.(anonymous function)base:1028
e.extend.eachbase:2
e.fn.e.eachbase:2
$.widget.bridge.$.fn.(anonymous function)base:1023
$.widget.enhancebase:1228
$.widget.enhanceWithinbase:1207
$.widget.options.themebase:5198
f.event.dispatchbase:3
f.event.add.h.handle.ibase:3
f.event.triggerbase:3
f.fn.extend.triggerbase:3
e.extend.eachbase:2
e.fn.e.eachbase:2
f.fn.extend.triggerbase:3
setPageContentcomponents:248
displayLoginbase:13133
loginbase:13230
f.Callbacks.nbase:2
f.Callbacks.o.fireWithbase:2
e.extend.readybase:2
c.addEventListener.B

这只发生在我尝试动态创建页面时。有谁知道为什么会这样?

4

1 回答 1

0

我看到的两件事是在下一行的末尾添加一个单引号和一个分号。

html += '<ul data-role="listview" data-theme="g"><li><a href="acura.html">Acura</a></li><li><a href="audi.html">Audi</a></li><li><a href="bmw.html">BMW</a></li></ul> //<- missing single quote and semi colon

更正:

html += '<ul data-role="listview" data-theme="g"><li><a href="acura.html">Acura</a></li><li><a href="audi.html">Audi</a></li><li><a href="bmw.html">BMW</a></li></ul>'; //<- There we go much better

尝试通过类似jshintjslint的方式运行您的 javascript,以帮助您识别此类错误。

于 2012-05-19T20:56:05.457 回答