백본 관계형이 너무 복잡해서 디버깅 할 수 없습니다. 이 자산을 사용하지 않으려 고합니다.게시와 관련된 의견이있는 간단한 블로그 백본 응용 프로그램 인 백본 관계형 사용을 피하는 방법
내 백본 앱에 두 개의 모음이 있습니다. - 포스트
가class Voice.Routers.Posts extends Backbone.Router
routes:
'': 'index'
initialize: ->
@collection = new Voice.Collections.Posts()
@collection.reset($('#container').data('posts').reverse())
index: ->
view = new Voice.Views.PostsIndex(collection: @collection)
$('#container').html(view.render().el)
내가 내 라우터는 포스트 ID로 URL (내 댓글에 따라 내 댓글 모음을 필터링하는 방법을 갖고 싶어 :
Voice.Collections.Posts
및
이 Voice.Collections.Comments
내 라우터 관계형 키, post_id) 그래서 기본적으로 "posts/12"(posts/: id)는 id를 취하고 'post_id'가 같은 주석 만 포함하는 주석 컬렉션을 초기화하는 showComments : (id) -> 함수를 호출합니다. ~ 12 ("id").
라우터에서 컬렉션을 정렬 할 수 있습니까? 이게 뭔가요? @comCollection가 intialized 될 필요가 있기 때문에 (이 나던 일)
class Voice.Routers.Posts extends Backbone.Router
routes:
'': 'index'
'post/:id/': 'showComments'
initialize: ->
@collection = new Voice.Collections.Posts()
@collection.reset($('#container').data('posts').reverse())
index: ->
view = new Voice.Views.PostsIndex(collection: @collection)
$('#container').html(view.render().el)
showComments: (id) ->
@comCollection = new Voice.Views.Collections.Comments()
@comCollection = @comCollection.where ->
@model.get('post_id') = id
comview = new Voice.Views.CommentsIndex(collection: @comCollection)
$('#comContainer').html(comview.render().el)
하지만이 작동하지 않습니다. 어떻게해야할지 모르겠습니다. 또한 다른 뷰 이벤트 트리거에서 뷰로 렌더링되는 주석 컬렉션을 해결할 것입니다. 도움을 주시면 감사하겠습니다.
편집 :
Backbone.navigate를 사용해야합니까? Backbone.navigate가 나쁜 냄새를 만듭니다.