I have the following setup for displaying my order by date:
I have the following template that shows each order for a given week: (I stripped some html for brevity)
Template:
{{#each ordersByDate in ordersByDateOfWeek}}
<div class="orders-by-date">
<div>
<span>{{order-date-formatted ordersByDate.date}}</span>
</div>
{{#each order in ordersByDate.orders}}
{{order.number}} {{! updates correctly}}
{{order.market.name}} {{! a hasmany property called here, does not update}}
{{/each}}
</div>
{{/each}
The computed property:
ordersByDateOfWeek: function () {
var result = []; // return value
var object = null
var date = null;
// add every order to an array with a date an order objects
this.forEach(function (order) {
// get the date of the order
date = order.get('created');
// create a new object that holds the orders for a given date
object = result.findProperty('date', date);
// create the object if it does not exist
if (!object) {
object = {
date: date,
orders: [],
// some more
};
// add the object with the date to the result
result.push(object);
}
// add the orders to the current object
object.orders.push(order);
// more calculations done here below
});
}.property('model', 'sortProperties', 'sortAscending'),
What it does is, that it creates an array of objects like this:
[
{
"date":"2014-12-08",
"orders":[// order objects here],
// some more properties
},
{
"date":"2014-11-08",
"orders":[],
},
{
"date":"2014-10-08",
"orders":[],
},
]
I am trying for hours now, and cannot get my head around it to get it to work. My intuition says that it has to do with promises? But in the "orders: []"
array are real Ember objects, so it should have to work I think.
I hope that someone can point me in the right direction.
Many thanks guys!
Edit: to be 100% clear: my order model consists solely of orders. That custom object do I create myself. Thats why the binding of data gets broken I think.