2015-01-04 4 views
1

Node.js 및 Express로 작성된 REST 서버에서 JSON 데이터를 가져 와서 Ember # Route에서 모델로 사용하려고합니다.Node + Express REST 서버에서 JSON을 가져올 때 Ember 데이터가 깨집니다.

데이터 내가 가져 오기 위해 노력하고 있습니다 :

var books = [ 
    { id: 98, author: 'Stanisław Lem', title: 'Solaris' }, 
    { id: 99, author: 'Andrzej Sapkowski', title: 'Wiedźmin' } 
]; 

내가 사용하는 모델 :

App.ApplicationAdapter = DS.RESTAdapter.extend({ 
    host: 'http://localhost:8080' 
}); 

매핑 :

나는 RESTAdapter이 방법을 설정

App.Book = DS.Model.extend({ 
    id: DS.attr('number'), 
    author: DS.attr('string'), 
    title: DS.attr('string') 
}); 

App.Router.map(function() { 
    this.resource("books"); 
}); 

내 경로는 다음과 같습니다

App.BooksRoute = Ember.Route.extend({ 
    model: function() { 
     return this.store.find('book'); 
    } 
}); 

나는 그것이 JSON 파일에 관해서 엠버 데이터가 특정 규칙을 따른다고 알고 있습니다.

http://localhost:8080/books 

를 입력 한 후,

app.get('/books', function (request, response) { 
    console.log('In GET function '); 
    response.json({'books': books}) 
}); 

그럼 난

{"books":[{"id":98,"author":"Stanisław Lem","title":"Solaris"},{"id":99,"author":"Andrzej Sapkowski","title":"Wiedźmin"}]} 

를 얻을 수 있지만, 내가 입력 할 때

http://localhost:8080/#/books 

엠버 데이터 예외 : 내 서버는 JSONs이 방법을 제공합니다 긴 오류 목록 t 모자는 다음으로 시작합니다 :

"Error while processing route: books" "invalid 'in' operand record._attributes"  
"[email protected]://localhost:8080/static/ember-data.js:8176:1 
ember$data$lib$system$model$attributes$$attr/<@http://localhost:8080/static/ember-data.js:8202:26 
[email protected]://localhost:8080/static/ember.prod.js:11882:15 
[email protected]://localhost:8080/static/ember.prod.js:11842:9 
makeCtor/[email protected]://localhost:8080/static/ember.prod.js:33887:17 
... 

이제는 무엇이 잘못되었고 어떻게 해결해야하는지 모릅니다.

답변

1

내가 만든 실수는 모델 선언에있는 것처럼 보입니다. ID 속성을 여기에 표시하면 안됩니다. 올바른 모델은 다음과 같습니다.

App.Book = DS.Model.extend({ 
    author: DS.attr('string'), 
    title: DS.attr('string') 
}); 
관련 문제