我是新的主幹和Rails。當我返回到最後一行的索引視圖時,索引視圖不會使用創建的新值更新。Backbone and Rails重定向
class App.Views.ProfilesIndex extends Backbone.View
template: JST['profiles/index']
initialize: ->
@collection.on('reset', @render, this)
render: ->
$(@el).html(@template(profiles: @collection))
this
這是我的新視圖
class App.Views.ProfilesNew extends Backbone.View
template: JST['profiles/new']
initialize: ->
@collection = new App.Collections.Profiles()
events: ->
'submit #new_profile': 'createProfile'
render: ->
$(@el).html(@template())
this
createProfile: (event) ->
event.preventDefault()
attributes = name: $('#new_profile_name').val()
@collection.create attributes,
success: -> Backbone.history.navigate("/profiles", {trigger: true})
所以,我需要創建並返回到索引視圖的新元素時更新集合代碼。
路由器
class App.Routers.Profiles extends Backbone.Router
routes:
'profiles': 'index'
'profiles/new': 'new'
initialize: ->
@collection = new App.Collections.Profiles()
@collection.fetch()
index: ->
view = new App.Views.ProfilesIndex(collection: @collection)
$('#container').html(view.render().el)
new: ->
view = new App.Views.ProfilesNew()
$('#container').html(view.render().el)
當我返回到最後一行的索引視圖時,索引視圖不會使用創建的新值更新。 – utiq 2012-08-02 17:45:56
我用路由器 – utiq 2012-08-03 00:58:57