Ember-Data "Findmany"가 올바르게 부가 해야하는 JSON 구조는 무엇입니까?

StackOverflow https://stackoverflow.com//questions/12679613

  •  12-12-2019
  •  | 
  •  

문제

ember-data와의 첫 번째 Hasmany 관계를하고 있으며 항상 재미있는 를 쳤습니다.

"잡히지 않은 오류 : 어설 션 실패 : 서버가 해시를 반환했습니다. 키 0이지만 매핑이 없습니다. "

이것은 일반적으로 "Ember"친숙한 형식이라고 부르는 JSON 구조가 없습니다.

Django rest framework를 사용하여 장고를 위해 Django를 위해 내 자신의 휴식 어댑터를 구축하고 있으므로 이것이 오류없이 sideload와 같은 것처럼 보이는 것을 궁금합니다.

현재 JSON은 아래에서 돌아 오는 것처럼 보입니다 (분명히 세션으로 되돌아가는 것은 아니지만 에스버가 이미이를 어떻게 철회하는 방법을 알고 있습니까?)

[{ "ID": 2, "이름": "foobar"}]

모델은 다음과 같습니다

CodeCamp.Session = DS.Model.extend({
    id: DS.attr('number'),
    name: DS.attr('string'),
    room: DS.attr('string'),
    desc: DS.attr('string')
});                 

CodeCamp.Speaker = DS.Model.extend({
    id: DS.attr('number'),
    name: DS.attr('string'),
    session: DS.belongsTo('CodeCamp.Session')
}); 

CodeCamp.Session.reopen({
    speakers: DS.hasMany('CodeCamp.Speaker')
});
.

미리 감사드립니다

도움이 되었습니까?

해결책

JSON 구조는 이렇게 보이는

{ speakers: [{ id: 2, name: "FooBar" }] }
.

이 커밋을 찾았습니다.이 커밋은 방금 이름이 지정된 Dict 에 내 JSON을 감쌀 필요가 있음을 보여줍니다.

https://github.com/kurki/data/commit/f59AD5BC9718634B6F3D59356DEAE0BF97A1BBD5 <./ P>

이제는 Django Adapter 에 내 사용자 정의 JSON 메서드입니다.

 findMany: function(store, type, ids) {
            var root = this.rootForType(type), plural = this.pluralize(root), json = {};
            this.django_ajax(this.buildURL(root, ids), "GET", {
                success: function(pre_json) {
                    json[plural] = pre_json;                                                                       
                    this.sideload(store, type, json, plural);
                    store.loadMany(type, json[plural]);
                }
            });
        }
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top