couchdb
과 함께 작동하는 RESTAdapter
을 빌드했으며 작동하는지 테스트하여 지금까지는 문제가없는 것처럼 보였지만 테스트 경로에는 다른 문제가있는 것으로 보입니다.Ember route가 성공한 후에 빈 모델을 얻었습니다
이 너무 오래, 아마 그것을 위해 바이올린을 설정한다고입니다 죄송합니다 ... 제가했습니다
.... 단지 그 전에 해본 적이 없다,하지만 지금 그것으로 볼 것이다
App.Thing = DS.Model.extend({
rev: DS.attr(),
price: DS.attr()
});
App.Things<Index>Route = Ember.Route.extend({
model: function() {
return this.get('store').findAll('thing');
}
});
(나는 변화없이 함께하고
Index
없이
ThingsRoute
을 시도했습니다)
App.Router.map
에서
:
,536,913,632 다음 (관련) 일을 내장 10this.resource('things', function() {
this.route('thing', { path: ':thing_id'})
});
App.ApplicationAdapter = DS.RESTAdapter.extend
에서 :
buildURL: function(type, id) {
id = id || '_all_docs?include_docs=true';
return this._super(type, id);
}
App.ApplicationSerializer = DS.RESTSerializer.extend
에서 :
extractArray: function(store, type, payload, id, requestType) {
root = type.typeKey;
root = Ember.String.pluralize(root);
newJSON = {};
newJSON[root] = payload.rows.map(function(row) {
return row.doc;
});
payload = newJSON;
console.log(payload);
return this._super(store, type, payload, id, requestType);
},
normalize: function(type, hash, property) {
var json = { id: hash._id, rev: hash._rev};
delete hash._id;
delete hash._rev;
for (var prop in hash) {
json[prop] = hash[prop];
}
console.log(json);
return this._super(type, json, property);
}
그리고이 템플릿 : 모두 완벽하게 포맷 된 다음 보여 extractArray
및 normalize
에서
<script type="text/x-handlebars" data-template-name="things/index">
{{#each thing in things}}
{{thing.rev}}
{{thing.price}}
{{else}}
Empty.
{{/each}}
</script>
console.log
의 및 올바른 JSON :
Object {things: Array[3]}
Object {id: "8117701d38cf9a1112ce8ed38000064d", rev: "1-14918623fedb103cf035ff2489e0a6a1", price: 1}
Object {id: "8117701d38cf9a1112ce8ed3800006e5", rev: "1-09b1e6aa1fb391e11c90bca86daccb7a", price: 5}
Object {id: "8117701d38cf9a1112ce8ed38000144e", rev: "1-2a682bf7ce58829ad2054bb8f5fbe869", price: 4}
하지만 템플릿이 렌더링 될 때 단순히 Empty
을 보여주고, 나는이에 ThingsRoute
에 model
후크를 교체 할 때 예상대로
return {things: [{id: 1, rev: 234, price: 4}, {id: 2, rev: 235, price: 3}]};
정확히 작동합니다. 내가 afterModel
를 정의 할 때 AND :
afterModel: function(things, transition) {
console.log(things);
console.log(transition);
}
그것은이 기록합니다 Class
목적이있다
Class {type: function, store: Class, isLoaded: true, isUpdating: false, toString: function…}
Transition {router: Router, promise: Promise, data: Object, resolvedModels: Object, providedModels: Object…}
것을 :
content: Array[3]
0: Class
1: Class
2: Class
그리고 그 Class
ES의 각각에 대응하는 id
필드가 내 사물.
무슨 일입니까? 왜 어댑터가 그 일을 완벽하게 수행 한 후에도 내 경로가 그 모델을 얻지 못합니까?
빙고가 모두 작동 했으므로, {{# 가지}}, {{컨트롤러의 모든 # 가지}}, – Kingpin2k
빙고를 사용할 수 있습니다. 필요하지 않으므로'모델 '로 변경하려고합니다. 어떤 여분의'js'가'things' 배열이 이름으로 전달되지 않는 이유를 설명 할 수 있습니까? 또한 단순히'{{#each thing}} '이 작동하지 않는 이유는 무엇입니까? 나는 여기서 뭔가를 놓치고있다. – blaineh
@Daniel'{{#each thing}}'이 (가) 작동하지 않았지만 {{컨트롤러의 모든 작업}}이 (가) 수행했습니다. – blaineh