Я использую модель ember для простого приложения-фактуры, я новичок в ember, и я не могу исправить то, что здесь происходит, в основном я использую hasMany модели ember для встроенных вложенных данных , (элементы для каждого счета-фактуры находятся в массиве), я попытался поместить код в jsbin и jsfiddle, но он не работает там, поэтому для тех, у кого есть время, чтобы помочь мне открыть архив на моем Dropbox здесь: Ember-Model hasMany not updating in template's {{#each}}Ember-Model 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"}
]
}];
Спасибо большое, я всегда удивляюсь, как просто решение кажется, или как глупо я .. Я пытался не устанавливать ID для элементов в моих светильниках, и он тоже работает. Еще раз спасибо. – Wilhearts