我是新的主干和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