Jquery mobile 主干及;Jquery Mobile渲染样式不起作用-用CoffeeScript编写
我正在使用主干jquerymobile和coffee脚本开发一个简单的twitter应用程序。我的问题是jquery mobile样式无法渲染。我的观点是Jquery mobile 主干及;Jquery Mobile渲染样式不起作用-用CoffeeScript编写,jquery-mobile,backbone.js,coffeescript,Jquery Mobile,Backbone.js,Coffeescript,我正在使用主干jquerymobile和coffee脚本开发一个简单的twitter应用程序。我的问题是jquery mobile样式无法渲染。我的观点是 class HomeView extends Backbone.View constructor: -> super initialize: -> @Twitter= new TwitterCollection template: _.template($('#home').html()) render: -
class HomeView extends Backbone.View
constructor: ->
super
initialize: ->
@Twitter= new TwitterCollection
template: _.template($('#home').html())
render: ->
@loadResults()
loadResults: ->
@Twitter.fetch({
success: (data) =>
$(@.el).html(@template({data: data.models, _:_}))
error: ->
alert('Error!')
})
这在从Twitter获取信息方面效果很好,但是当
$(@.el).html(@template({data: data.models, _:_}))
在fetch函数中,jquerys样式不呈现。有人能告诉我如何更新样式吗?非常感谢您的帮助
作为参考,html模板为:
<script type="text/template" id="home">
<div data-role="header" data-position="fixed">
<h1>TWITTER DATA</h1>
</div>
<div data-role="content">
<ul data-role="listview" data-inset="true">
<% _.each(data, function (row) { %>
<li><a href="#tweet-<%= row.get('id') %>"><%= row.get('text') %></a></li>
<% }); %>
</ul>
</ul>
</div>
推特数据
好的,我通过将“.listview('refresh').trigger('create');”添加到
$(@.el).html(@template({data: data.models, _:_}))
好的,我通过将“.listview('refresh').trigger('create');”添加到
$(@.el).html(@template({data: data.models, _:_}))
当随后应用修复程序时(在视图页面被
$.mobile.changePage()
呈现和显示之后),用户会得到一个不愉快的副作用:视图会因jquery mobile应用的样式更改而闪烁
我的解决方案是在动态渲染完成后从视图触发自定义事件,并将$.mobile.changePage()
绑定到该事件。这将导致输出被“缓冲”直到完成,然后完全设置样式
下面是一个例子:
在我的视图的initialize
函数中,我有一段代码等待获取时模型/集合触发一个事件,还有一个函数用于呈现html的动态部分:
window.MyView = Backbone.View.extend({
// some other code here
initialize: function() {
this.listenTo(this.collection, "fetchCompleted:CollectionName", this.renderRows);
},
renderRows: function (eventName) {
$(this.el).find('div[class="content-primary"]').html(this.template_ul({data: this.collection}));
this.trigger( 'view:ready' );
},
//...
。。。然后在路由器中,我为changePage()
提供了以下代码:
当随后应用修复程序时(在视图页面被
$.mobile.changePage()
呈现和显示之后),用户会得到一个不愉快的副作用:视图会因jquery mobile应用的样式更改而闪烁
我的解决方案是在动态渲染完成后从视图触发自定义事件,并将$.mobile.changePage()
绑定到该事件。这将导致输出被“缓冲”直到完成,然后完全设置样式
下面是一个例子:
在我的视图的initialize
函数中,我有一段代码等待获取时模型/集合触发一个事件,还有一个函数用于呈现html的动态部分:
window.MyView = Backbone.View.extend({
// some other code here
initialize: function() {
this.listenTo(this.collection, "fetchCompleted:CollectionName", this.renderRows);
},
renderRows: function (eventName) {
$(this.el).find('div[class="content-primary"]').html(this.template_ul({data: this.collection}));
this.trigger( 'view:ready' );
},
//...
。。。然后在路由器中,我为changePage()
提供了以下代码:
控制台中是否有错误消息?控制台中是否有错误消息?