2014-06-19 2 views
1

나는 Ember JS 앱에 연결하고 싶은 REST endpoint 인 "http://localhost:8080/customers"을 가지고있다.Ember js가 HATEOAS REST API와 함께 작동

App.Store = DS.Store.extend({ 
revision: 12, 
adapter: DS.RESTAdapter.extend({ 
url: 'http://localhost:8080/customers' 
}) 
}); 

REST 페이로드

{ 
    "_links" : { 
    "search" : { 
     "href" : "http://localhost:8080/customers/search" 
    } 
    }, 
    "_embedded" : { 
    "customers" : [ { 
     "id" : 2, 
     "firstName" : "Jim", 
     "lastName" : "Smith", 
     "_links" : { 
     "self" : { 
      "href" : "http://localhost:8080/customers/2" 
     } 
     } 
    }, { 
     "id" : 1, 
     "firstName" : "Jimmy", 
     "lastName" : "Jones", 
     "_links" : { 
     "self" : { 
      "href" : "http://localhost:8080/customers/1" 
     } 
     } 
    } ] 
    } 
} 

나는이 오류가 계속. Ember JS의 두 번째 주입니다. 솔직히 말해서 이것은 상상했던 것보다 훨씬 더 어렵습니다. 디버깅이나 이해하기가 쉽지 않습니다.

오류로드하는 동안 경로 :

{ 
    "customers" : [ 
    { 
     "id" : 2, 
     "firstName" : "Jim", 
     "lastName" : "Smith" 
    }, { 
     "id" : 1, 
     "firstName" : "Jimmy", 
     "lastName" : "Jones" 
    } 
    ] 
} 

당신이 사용하는 방법을 설명 https://github.com/emberjs/data/blob/master/TRANSITION.md을 읽을 수 있습니다 :

TypeError: undefined is not a function 
at App.CustomersRoute.Ember.Route.extend.model 
+0

, 경로 및 모델 정의를 포함하십시오. – Kingpin2k

+0

이제 새로운 오류가 발생합니다. 경로를로드하는 중에 오류가 발생했습니다. TypeError : 정의되지 않은 'find'속성을 읽을 수 없습니다. – user3754920

+0

http://emberjs.jsbin.com/OxIDiVU/73/edit 여기에서 수행중인 작업을 보여주기위한 템플릿이 있으므로 잘못된 정보를 찾을 수 있습니다. . – Kingpin2k

답변

0

는 기본적으로 사용자 지정 serializer를 사용하여이 형식으로 데이터를 변환 할 필요가 extractSingle, extractArray, normalize, normalizeHash.

당신은 특별한 예는 API의 예를 가까이 보이는 위치 : 엠버 데이터의 정말 오래된 버전의 이 http://emberjs.com/api/data/classes/DS.RESTSerializer.html#method_extractArray

App.CustomerSerializer = DS.ActiveModelSerializer.extend({ 
    extractArray: function(store, type, payload) { 
    // do your own implementation and return that, or modify it slightly 
    // and do the default implementation 
    return this._super(store, type, payload); 
    }, 
});