【发布时间】:2015-02-06 20:22:06
【问题描述】:
我正在尝试在社交提要上开发刷新功能,每分钟我都会检查是否有一些新推文。
我正在获取主干集合 (col1),1 分钟后我正在获取相同的集合 (col2) 以比较和提取新推文。
@tweets = App.request "tweets:entities"
that = @
setInterval (->
that.freshTweetsCol = App.request "tweets:entities"
App.execute "when:fetched", that.freshTweetsCol, =>
console.log(that.freshTweetsCol == that.tweets)
freshTweets = _(that.freshTweetsCol.models).without(that.tweets.models)
freshTweets2 = _.difference(that.freshTweetsCol.toJSON(),that.tweets.toJSON())
console.log(freshTweets)
console.log(freshTweets2)
return
), 10000
- @tweets 给我收集了 20 个模型
- that.freshTweetsCol 为我提供了与 20 个模型相同的集合 在@tweets 中,如果没有新推文。
- console.log(that.freshTweetsCol == that.tweets) 给出错误,即使模型相同
- console.log(freshTweets) 为我提供了 20 个模型的数组,每个模型都称为“Tweet”
- console.log(freshTweets2) 给了我 20 个对象的数组
我怎样才能只检查新推文?为什么我不能使用 _.difference 方法来比较集合?
【问题讨论】:
标签: backbone.js collections coffeescript marionette