2015-01-28 1 views
1

EmberJS와 함께 놀고 있고, 지금 당장 노선을 통해 어떤 행동을 이해하려고합니다.동적 경로가있는 모델의 객체를 패키징하는 것은 정의되지 않습니다 - 이유는 무엇입니까?

저는 Rdio API에 연결하고 다양한 아티스트의 앨범/노래를 표시하려는 의도로 테스트 응용 프로그램을 구축하고 있습니다. 지수 (사용 가능한 모든 앨범의 목록) 및 개인 앨범보기 :

Here's a JsBin.

는 지금, 두 견해가있다.

App.ALBUMS = { 
"status": "ok", 
"result": [ 
    { 
    "key": "a5337866", 
    "icon": "http://rdio3img-a.akamaihd.net/album/a/0/3/000000000051730a/3/square-200.jpg", 
    "artist": "The Decemberists", 
    }, 
    { 
    "key": "a5229271", 
    "icon": "http://rdio1img-a.akamaihd.net/album/7/d/a/00000000004fcad7/1/square-200.jpg", 
    "artist": "Nicki Minaj", 
    }, 
    ] 
}; 

... 인덱스가 잘 작동합니다 ...

App.Router.map(function() { 
    this.route("album", { path: "/album/:key" }); 
}); 

을 그리고 다음과 같습니다 고정물을 제공 :

동적 경로과 같이 정의된다

App.IndexRoute = Ember.Route.extend({ 
    model: function() { 
    return {albums:App.ALBUMS.result } 
    } 
}); 

(내가 의도적으로 패키지 한 App.ALBUMS.result 개체에 내가 나중에에 더 많은 정보를 포장 할 수 O) 나는 앨범보기에 도착하면

Lyrically Index Page

그러나, 나는이 문제가 얻을 :. 어떤해야한다 (

App.AlbumRoute = Ember.Route.extend({ 
    model: function(params){ 
    console.log(params); 
    console.log(App.ALBUMS.result.findBy('key',params.key)); //Logs object just fine 
    return App.ALBUMS.result.findBy('key',params.key); //ERROR 
    } 
}); 

포장 값을 반환 이미 두 번째 객체 또는 배열에있는 객체입니다).

// THIS WORKS!: 
return [App.ALBUMS.result.findBy('key',params.key)]; 
// THIS AlSO WORKS!: 
return {album: App.ALBUMS.result.findBy('key',params.key)}; 

왜?

App.ALBUMS.result.findBy ('키', params.key) 혼자 (이며) 객체를 반환, 그렇게해야하는 이유를 그 위에 엠버 초크합니까?

오류 자체가 오히려 도움이되지 않는 것입니다 : 모델은 엠버 객체 인 경우

 Error while processing route: album undefined is not a function TypeError: undefined is not a function 
    at EmberObject.extend._setupArrangedContent (http://local.lyrically.com/js/libs/ember-1.9.1.js:34181:27) 
    at null._arrangedContentDidChange (http://local.lyrically.com/js/libs/ember-1.9.1.js:34167:14) 
    at applyStr (http://local.lyrically.com/js/libs/ember-1.9.1.js:19677:29) 
    at sendEvent (http://local.lyrically.com/js/libs/ember-1.9.1.js:14115:13) 
    at notifyObservers (http://local.lyrically.com/js/libs/ember-1.9.1.js:17488:9) 
    at propertyDidChange (http://local.lyrically.com/js/libs/ember-1.9.1.js:17291:7) 
    at iterDeps (http://local.lyrically.com/js/libs/ember-1.9.1.js:17373:11) 
    at dependentKeysDidChange (http://local.lyrically.com/js/libs/ember-1.9.1.js:17329:9) 
    at propertyDidChange (http://local.lyrically.com/js/libs/ember-1.9.1.js:17287:9) 
    at iterDeps (http://local.lyrically.com/js/libs/ember-1.9.1.js:17373:11) 

답변

0

엠버는 (분명히)를 좋아한다. 좋은 소식은 엠버 개체의 인스턴스로 일반 개체를 변환하는 것은 매우 쉬운 것입니다 - 당신은 그냥 다음

return Ember.Object.create(Lyrically.ALBUMS.result.findBy('key',params.key));

수정 문제를 반환, 따라서

Ember.create(yourRegularObject)을한다.

실무 데모 here