如何使用来自服务器的新数据更新帖子集合handleSliderChange()
?当我尝试fetch()
在$.getJSON
集合中使用时,会使用旧数据重置。
define ['jquery','backbone','app','views/posts/post_view','templates/posts/index'],
($, Backbone, App, PostsView) ->
class App.Views.Posts.IndexView extends Backbone.View
template: JST["posts/index"]
events:
"slidechange #slider": "handleSliderChange"
initialize: () ->
@options.posts.on('reset', @render, @)
addAll: () ->
@options.posts.each(@addOne, this)
addOne: (post) ->
view = new PostView({model: post})
$(@el).find("#list").append(view.render().el)
slider: ->
$(@el).find("#slider").slider({})
handleSliderChange: (e, ui) ->
self = this
$.getJSON "/posts?scope="+ui.value, (data) ->
#how to update posts collection with 'data'?
render: ->
$(@el).html(@template(posts: @options.posts.toJSON()))
@slider()
@addAll()
@