【发布时间】:2012-04-11 07:35:14
【问题描述】:
我有一个有很多子模型的父模型,例如:
App.Blog = Ember.Object.extend({})
App.Comment = Ember.Object.extend({})
然后我对博客有一个看法:
window.App.BlogView = Ember.View.extend
templateName: 'app_templates_blog'
现在,当我最初通过 REST API 检索博客时,它包含前 10 条左右的评论。这些实例化如下:
window.App.Blog.reopenClass
create: (obj) ->
Object.tap @_super(obj), (result) =>
if result.comments
result.comments = result.comments.map (p) => App.Comment.create(p)
我通过调用 BlogView.set('blog', blogInstance) 按博客显示,一切都完美显示。
但是!
我正在实现无限滚动,所以当最终用户到达 cmets 的底部时,我想加载更多。我通过 REST 执行此操作,但我无法通过附加它们来显示它们。
这就是我的 morePosts() 方法在 BlogView 中的样子:
moreComments: () ->
blog = @get('blog')
jQuery.getJSON "/blogs/#{blog.get('id')}/comments", (result) =>
comments = blog.get('comments')
result.each (c) => comments.push(App.Comment.create(c))
blog.set('comments', comments)
this.set('blog', blog)
但是,这似乎永远不会添加新的 cmets。我在这里做错了什么?
【问题讨论】:
标签: coffeescript ember.js