我將模板附加到body,這在jquery mobile中呈現良好。然而,我再通過數據環路和渲染個人的觀點 - 在jQuery Mobile的現在失敗..Backbone jquery移動渲染 - 在CoffeeScript中
本來我使用列表視圖(「刷新」),但我得到這個錯誤,「jquerymobile錯誤「不能調用之前ListView的方法初始化「,當循環一個全新的視圖時......還實現觸發器(」創建「)似乎也不工作,無論我把它放在哪裏...也許我錯了,如果是的話,你可以告訴我在哪裏穿上它,或解釋如何可以是固定的...
另一個問題曾建議這樣做......但我不知道在哪裏放置它,如果它的工作原理:
$('#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阿爾法...
任何幫助將非常感激,感謝