Jquery mobile 主干jquery移动渲染-在CoffeeScript中
我在正文中添加了一个模板,这在jquery mobile中表现得很好。然而,我随后循环遍历数据并呈现单个视图——jquery mobile现在失败了 最初我使用listview(“refresh”),但是我遇到了这样一个错误,“jquerymobile error”在初始化之前不能调用listview上的方法,”,当循环通过一个全新的视图时……也实现了触发器(“create”)无论我把它放在哪里,它似乎都不起作用…也许我错了,如果是的话,你能告诉我放在哪里,或者解释一下如何修复它 另一个问题建议这样做……但我不确定放在哪里,以及它是否有效:Jquery mobile 主干jquery移动渲染-在CoffeeScript中,jquery-mobile,backbone.js,coffeescript,Jquery Mobile,Backbone.js,Coffeescript,我在正文中添加了一个模板,这在jquery mobile中表现得很好。然而,我随后循环遍历数据并呈现单个视图——jquery mobile现在失败了 最初我使用listview(“refresh”),但是我遇到了这样一个错误,“jquerymobile error”在初始化之前不能调用listview上的方法,”,当循环通过一个全新的视图时……也实现了触发器(“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 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()
)
作为参考,我使用jqm1.2.0alpha
非常感谢您的帮助,谢谢我想每次在
FavoriteSListView
中运行render
方法时,您都可能会删除您的列表视图。每次创建新的
时,您都必须在其上重新触发create
。理想情况下,您应该保留ul
e在获取
完成后,只交换内部li
元素。然后在$(“#favList”).listview('refresh')
元素卡在其中时执行$
但是,这需要进行一些重大的返工,因此,请尝试使用现有代码:
class FavouritesListView extends Backbone.View
initialize: =>
Favourites.fetch()
template: _.template($('#propertyFavourites').html())
render: =>
@$el.append(@template)
@addFavs()
addFavs: =>
# FYI: @$(...) is shorthand for this.$el.find(...)
$favList = @$("#favList")
Favourites.each (fav) =>
view = new FavouriteView({model: fav})
# TODO: batch these up and only do one append at the end for better performance.
$favList.append(view.render().el)
# Move this trigger out of the for loop, only trigger at the end.
# Sometimes triggering create on the parent is better, not the actual list.
@$el.trigger "create"
我还根据一些新的主干功能调整了一些东西,如this.$el==$(this.el)
和this.$(…)==this.$el.find(…)
是等效的速记,更好地使用。我认为每次运行收藏夹列表视图中的呈现方法时,您可能会删除列表视图。每次创建新的
时,您都必须在其上重新触发创建。理想情况下,您会保留该>ul
元素,仅在获取
完成时交换内部li
元素。然后在$('#favList')。listview('refresh')
元素卡在其中时执行$('favList')。listview('refresh')
但是,这需要进行一些重大的返工,因此,请尝试使用现有代码:
class FavouritesListView extends Backbone.View
initialize: =>
Favourites.fetch()
template: _.template($('#propertyFavourites').html())
render: =>
@$el.append(@template)
@addFavs()
addFavs: =>
# FYI: @$(...) is shorthand for this.$el.find(...)
$favList = @$("#favList")
Favourites.each (fav) =>
view = new FavouriteView({model: fav})
# TODO: batch these up and only do one append at the end for better performance.
$favList.append(view.render().el)
# Move this trigger out of the for loop, only trigger at the end.
# Sometimes triggering create on the parent is better, not the actual list.
@$el.trigger "create"
我还根据一些新的主干功能对一些东西进行了调整,比如this.$el==$(this.el)
和this.$(…)==this.$el.find(…)
是更好使用的等效速记