2013-07-28 9 views
0

Ember가 동일한 경로 모델을 계속해서 경로에 추가하는 문제가 있습니다.동일한 모델을 경로에 추가하는 Ember

# ROUTER 
MediaUi.Router.map(function() { 
    this.route('movie', { path: '/movie/:id' }); 
}); 

# ROUTE 
MediaUi.IndexRoute = Ember.Route.extend({ 
    'model': function() { 
    return MediaUi.Media.find(); 
    } 
}); 

# MODEL 
MediaUi.Media = DS.Model.extend({ 
    'type':  DS.attr('string'), 
    'title': DS.attr('string'), 
    'director': DS.attr('string'), 
    'year':  DS.attr('number'), 
    'url':  DS.attr('string'), 
    'media': DS.attr('string'), 
    '_id':  DS.attr('string'), 
    'description': DS.attr('string', { 'defaultValue': 'TBD' }) 
});x 

DS.RESTAdapter.map('MediaUi.Media', { 
    'id': { 'key': '_id' } 
}); 

DS.RESTAdapter.reopen({ 
    url: 'http://localhost:3000' 
}); 


#TEMPLATE 
<table class="table"> 
    <thead> 
     <tr> 
      <th>Title</th> 
      <th>Description</th> 
      <th>Actions</th> 
     </tr> 
    </thead> 
    {{#each item in model}} 
    <tr {{ bindAttr data-id="item._id" }}> 
     <td>{{#linkTo 'movie' item }} {{ item.title }} {{/linkTo}}</td> 
     <td><p>{{ item.description }}</p></td> 
     <td> 
      <button {{ action "launchModal" item target="view" }} class="btn btn-info">More Information</button> 
      <button class="btn btn-warning">Edit</button> 
      <button class="btn btn-danger">Remove</button> 
     </td> 
    </tr> 
    {{/each}} 
</table> 

{{ view MediaUi.ModalView }} 

# JSON 


{ 
    "medias": [ 
    { 
     "type": "movie", 
     "title": "The Dark Knight", 
     "director": "Christopher Nolan", 
     "year": 2008, 
     "url": "http://www.imdb.com/title/tt0468569/", 
     "media": "Blu-ray", 
     "_id": "51e2fc1b4c19500de6000001" 
    }, 
    { 
     "type": "movie", 
     "title": "Inception", 
     "director": "Christopher Nolan", 
     "year": 2010, 
     "url": "http://www.imdb.com/title/tt1375666/", 
     "media": "Blu-ray", 
     "_id": "51e2fc1b4c19500de6000002" 
    }, 
    { 
     "type": "movie", 
     "title": "The Dark Knight Rises", 
     "director": "Christopher Nolan", 
     "year": 2012, 
     "url": "http://www.imdb.com/title/tt1345836/", 
     "media": "Blu-ray", 
     "_id": "51e2fc1b4c19500de6000003" 
    }, 
    { 
     "type": "movie", 
     "title": "Django Unchained", 
     "director": "Quentin Tarantino", 
     "year": 2012, 
     "url": "http://www.imdb.com/title/tt1853728/", 
     "media": "Blu-ray", 
     "_id": "51e2fc1b4c19500de6000004" 
    }, 
    { 
     "type": "movie", 
     "title": "City of God", 
     "director": "Kátia Lund,Fernando Meirelles", 
     "year": 2002, 
     "url": "http://www.imdb.com/title/tt0317248/", 
     "media": "DVD", 
     "_id": "51e2fc1b4c19500de6000005" 
    } 
    ] 
} 

이것은 다음이 충족 될 때 발생합니다

  • 사용자 Transitione가 특정 페이지를 모델 ('영화/: movie_id')는
  • 사용자는 브라우저에서 뒤로 버튼을 클릭하거나 클릭하는 linkTo 핸들 바 헬퍼로 만든 응용 프로그램의 뒤로 버튼

어떤 도움을 주시면 감사하겠습니다. 감사!

답변

0

누구든지이 문제를 접한다면, 이는 백엔드와 관련이있을 수 있습니다. 필자의 경우 MongoDB는 식별자로 ID가 아닌 id를 사용하고 Ember는 id를 레코드의 기본 키 유지 트랙으로 연결합니다. 따라서이 차이점을 직렬화하고 응용 프로그램을 적절하게 구성하는 어댑터를 만들어야합니다.

MediaUi.Adapter = DS.RESTAdapter.extend({ 
    serializer: DS.RESTSerializer.extend({ 
    primaryKey: function(type){ 
     return '_id'; 
    } 
    }) 
}); 

MediaUi.Store = DS.Store.extend({ 
    revision: 11, 
    adapter: 'MediaUi.Adapter' 
}); 

참조 : Ember, Ember Data and MongoDB's _id

내 경우

나는 다음을 수행했다

관련 문제