2013-11-23 2 views
0

템플릿의 각 도우미에서 업데이트하지, 난 엠버 새로운 오전과 나는 기본적으로 내가 포함 된 중첩 된 데이터 엠버 모델의 hasMany의를 사용하고, 여기에 무슨 일이 일어나고 있는지 고칠 수 (각 송장에 대한 항목을 배열에), 나는 jsbin와 jsfiddle에 코드를 넣어 시도하지만 난 여기에 내 보관함에 보관을 넣어 도움이 시간이 사람들 그래서, 거기 작동하지 않습니다 Ember-Model hasMany not updating in template's {{#each}}엠버 - 모델 EmbeddedHasManyArray 내가 간단한 송장 앱 엠버 모델을 사용하고

버그를 재현하려면 인보이스로 이동 한 다음 링크를 사용하여 다른 인보이스로 이동하고 멈추지 않는 것처럼 업데이트하지 않는 항목을보고 페이지를 새로 고침하면 올바른 항목을 얻을 수 있습니다. 잘못하고있다 : /? .. 기꺼이 도울 사람에게

감사

다음 코드는 물론 내 실제 응용 프로그램의 매우 단순화 된 버전이지만 버그를 재현한다.

Index.html을

<!DOCTYPE html> 
<html> 
<head> 
    <meta name="description" content="Ember - Starter" /> 
    <meta charset=utf-8 /> 
    <title>Ember-Model</title> 
    <script src="libs/jquery-1.9.1.js"></script> 
    <script src="libs/handlebars-1.0.0.js"></script> 
    <script src="libs/ember-1.1.2.js"></script> 
    <script src="libs/ember-model-latest.js"></script> 
    <script src="app.js"></script> 
</head> 
<body> 

<script type="text/x-handlebars"> 
    <h1>Invoices</h1> 
    {{ outlet }} 
</script> 

<script type="text/x-handlebars" data-template-name="factures"> 
{{#each}} 
    <ul> 
     <li>{{#link-to 'facture' this}}{{title}}{{/link-to}}</li> 
    </ul> 
{{/each}} 
    <hr/> 
    {{outlet}} 
</script> 

<script type="text/x-handlebars" data-template-name="facture"> 
<h2>Items for {{title}}</h2> 
{{#each items}} 
<ul> 
    <li>{{desc}}</li> 
</ul> 
{{/each}} 
</script> 

</body> 
</html> 

App.js

var App = Ember.Application.create(); 

// ROUTER 
App.Router.map(function() { 
    this.resource('factures', function() { 
     this.resource('facture', { 
      path: '/:facture_id' 
     }); 
    }); 
}); 

App.FacturesRoute = Ember.Route.extend({ 
    model: function (params) { 
     return App.Facture.find(); 
    } 
}); 

App.FactureRoute = Ember.Route.extend({ 
    model: function (params) { 
     return App.Facture.fetch(params.facture_id).then(function (modelData) { 
      return App.Facture.find(params.facture_id); 
     }); 
    } 
}); 

// Redirect 
App.IndexRoute = Ember.Route.extend({ 
    redirect: function() { 
     this.transitionTo('factures'); 
    } 
}); 


// MODELS 
var attr = Ember.attr, 
    hasMany = Ember.hasMany, 
    belongsTo = Ember.belongsTo; 

// Factures 
App.Facture = Ember.Model.extend({ 
    title: attr(), 
    items: hasMany('App.Item', { 
     key: 'items', 
     embedded: true 
    }) 
}); 

App.Facture.adapter = Ember.FixtureAdapter.create(); 

// Facture 
// -> [ Items ] 
App.Item = Ember.Model.extend({ 
    desc: attr(""), 
    qty: attr("number"), 
    price: attr("string") 
}); 

// FIXTURES 

App.Facture.FIXTURES = [ 
{ 
    id: 1, 
    title: "Invoice #1", 
    items: [ 
     {id: 1, desc: 'An Item for #1', qty: 2, price: "45"}, 
     {id: 2, desc: 'An Item for #1', qty: 5, price: "75"} 
    ] 
}, 
{ 
    id: 2, 
    title: "Invoice #2", 
    items: [ 
     {id: 1, desc: 'An Item for #2', qty: 2, price: "250"}, 
     {id: 2, desc: 'An Item for #2', qty: 5, price: "200"} 
    ] 
}]; 

답변

0

는 동일한 ID를 보는 경우 귀하의 항목 아이디의 그것이 포함되거나 있지 않다면, 엠버 모델은 상관하지 않는 고유해야합니다 그것 해당 id에 대해 이미 존재하는 모델을 반환합니다. 당신이 App.Facture.fetch()App.Facture.find()을 포장하는 이유

http://emberjs.jsbin.com/eKibapI/1/edit

App.Facture.FIXTURES = [ 
{ 
    id: 1, 
    title: "Invoice #1", 
    items: [ 
     {id: 1, desc: 'An Item for #1', qty: 2, price: "45"}, 
     {id: 2, desc: 'An Item for #1', qty: 5, price: "75"} 
    ] 
}, 
{ 
    id: 2, 
    title: "Invoice #2", 
    items: [ 
     {id: 3, desc: 'An Item for #2', qty: 2, price: "250"}, 
     {id: 4, desc: 'An Item for #2', qty: 5, price: "200"} 
    ] 
}]; 
+0

덕분에 많이, 내가 솔루션이 될 것으로 보인다 얼마나 간단한 지 항상 놀란다, 또는 얼마나 바보 같은 내가 ... 내가 내 비품에있는 항목의 모든 ID를 설정하지 않는 시도하고 너무 작동 않습니다. 다시 한번 감사드립니다. – Wilhearts

0

잘 모르겠어요. 방법은 당신의 model 훅에 의해 반환되지 않습니다 콜백 함수의 return을 설정합니다. 다음보십시오 : 당신은 단지 전체 App.FactureRoute 제거 할 수 있어야한다, 그래서 물론

App.FactureRoute = Ember.Route.extend({ 
    model: function (params) { 
     return App.Facture.find(params.facture_id); 
    } 
}); 

이 또한 기본 동작입니다.

+0

내 응용 프로그램에서 템플릿이 항목을 받기 전에 렌더링하는 데 사용하기 때문에이 약속을 반환하는이 일을하고, 약속이 이루어집니다 (앱이 LoadingRoute에 남아) 모든 것이 괜찮 전에 템플릿을 렌더링하지 않습니다 이런 식으로. – Wilhearts

+0

대신 App.Facture.find ({id : params.facture_id})를 수행 할 수 있어야합니다. 내가 틀렸다고 생각하지 않는다면 약속을 되찾아 야합니다. – chopper

+0

가 그래 나는이 가져오고 지금 작동하는 것 같다에서 중첩없이 시도, 내가 혼란 스러워요>< – Wilhearts