2013-10-19 14 views
2

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 다음 (관련) 일을 내장 10
this.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); 
} 

그리고이 템플릿 : 모두 완벽하게 포맷 된 다음 보여 extractArraynormalize에서

<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을 보여주고, 나는이에 ThingsRoutemodel 후크를 교체 할 때 예상대로

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 필드가 내 사물.

무슨 일입니까? 왜 어댑터가 그 일을 완벽하게 수행 한 후에도 내 경로가 그 모델을 얻지 못합니까?

답변

1

을 찾아 사용한다 당신이 컨트롤러의 별칭을 만들 수있는 변수를 원하는 :

App.ThingsIndexController = Ember.ArrayController.extend({ 
    things: Ember.computed.alias('model') 
}); 
+1

빙고가 모두 작동 했으므로, {{# 가지}}, {{컨트롤러의 모든 # 가지}}, – Kingpin2k

+0

빙고를 사용할 수 있습니다. 필요하지 않으므로'모델 '로 변경하려고합니다. 어떤 여분의'js'가'things' 배열이 이름으로 전달되지 않는 이유를 설명 할 수 있습니까? 또한 단순히'{{#each thing}} '이 작동하지 않는 이유는 무엇입니까? 나는 여기서 뭔가를 놓치고있다. – blaineh

+0

@Daniel'{{#each thing}}'이 (가) 작동하지 않았지만 {{컨트롤러의 모든 작업}}이 (가) 수행했습니다. – blaineh

0

대신 findall은

의 난 당신의 문제는 템플릿에서 things 변수가 존재하지 않기 때문에, model

<script type="text/x-handlebars" data-template-name="things/index"> 
    {{#each thing in model}} 
     {{thing.rev}} 
     {{thing.price}} 
    {{else}} 
     Empty. 
    {{/each}} 
</script> 

에 또는 경우 업데이트하려고이라고 생각

+0

그냥 그것을 시도를하고 아무것도 변경하지 않은 :/ – blaineh

+0

당신이 연관이 있습니까 컨트롤러? – Kingpin2k

+0

컨트롤 로직이 없기 때문에 필자는 그것이 필요하다고 생각하지 않았습니다. Ember는이 모든 것을 암시 적으로 명명했습니다. 그게 효과를 낼 수있는 이유가 있을까요? – blaineh

관련 문제