1
一個父模型我有有許多兒童模特父母的模型,例如:附加兒童模特在Ember.js
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(「博客」,blogInstance),一切都完美顯示。
但是!
我正在實現無限滾動,所以當最終用戶到達註釋底部時,我想要加載更多。我通過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)
然而,這似乎永遠不會添加新的註釋。我在這裏做錯了什麼?
工作很好,謝謝! – 2012-03-28 00:51:37