【发布时间】:2012-08-31 09:22:23
【问题描述】:
我在正文中附加了一个模板,这在 jquery mobile 中可以很好地呈现。但是,然后我循环遍历数据并呈现单个视图 - jquery mobile 现在失败了..
最初我使用 listview("refresh"),但是当循环一个全新的视图时,我得到了这个错误,“jquerymobile 错误“无法在初始化之前调用 listview 上的方法”......还有实现 trigger("create") 似乎在我放置它的任何地方都不起作用......也许我错了,如果是这样,你能告诉我把它放在哪里,或者解释如何解决这个问题......
另一个问题建议这样做......但我不确定将它放在哪里,以及它是否有效:
$('#myListview').bind('pageinit', function() {
$('#myListview').listview('refresh');
});
我真的被卡住了.. 谁能解释一下如何解决这个问题,谢谢!
我的主要视图循环通过较小的视图是..
class FavouritesListView extends Backbone.View
initialize: =>
Favourites.fetch()
template: _.template($('#propertyFavourites').html())
render: =>
$(@el).append(@template)
@addFavs()
addFavs: =>
Favourites.each (fav) =>
view = new FavouriteView({model: fav})
$("#favList", @el).append(view.render().el)
#I've tried $("#favList", @el).append(view.render().el).listview("refresh") & get "cannot call methods on listview prior to initialization".. I've also tried .trigger("create") which doesn't work..
我的列表项视图是(在没有样式的情况下呈现)...
class FavouriteView extends Backbone.View
template: _.template($('#propertyFav').html())
render: =>
$(@el).html(@template({row: @model}))
@
我的路由器和应用程序是这样加载的..
class AppRouter extends Backbone.Router
routes:
"": "home"
"favourites": "favourites"
initialize: ->
#handle back buttons
$('.back').live('click', (event) ->
window.history.back();
false
)
@firstPage = true;
home: ->
@changePage(new HomeView())
favourites: ->
@changePage(new FavouritesListView())
changePage: (page, theTransition) ->
$(page.el).attr('data-role', 'page')
page.render()
$('body').append($(page.el))
if theTransition is undefined
transition = $.mobile.defaultPageTransition
else
transition = theTransition
#We don't want the first page to slide in
if @firstPage
transition = 'none'
@firstPage = false
$.mobile.changePage($(page.el), {changeHash: false, transition: transition})
$(document).ready( ->
AppRouter = new AppRouter()
Backbone.history.start()
)
作为参考,我使用的是 jqm 1.2.0 Alpha...
任何帮助将不胜感激,谢谢
【问题讨论】:
标签: jquery-mobile backbone.js coffeescript