Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember 1.5 How do I combine two record arrays?

In my application I have a feed of items. Lets just says these two items are Tasks and Purchases.

In my feed I want both of these items to populate an array that is sorted by date. They both have similar properties, such as title, and date. As far as displaying them on the UI I have no doubt i will be able to figure that out.

The problem is getting the records.

store.find('task');
store.find('purchase');

Both of these return promise arrays. I assume I will need some sort of array proxy. But my current code will not update the array everytime a property is modified on an object in either of these arrays. And it will also not render correctly or change when objects are added to these stores.

Has anyone had any luck merging two record arrays into one? And having it function as if it were just one record array which updates on the fly perfectly with everychange to the array and the objects within.

Any help appreciated! If need more code i will post!

UPDATE::

Attached is a JSBIN that should display what I am trying to do, and the fact that it is not working.

http://emberjs.jsbin.com/jebugofo/2/edit?html,js,console,output

like image 449
bmeyers Avatar asked May 02 '14 07:05

bmeyers


1 Answers

Here is your fiddle modified.

Im new to ember data. But from what I understand, you are merging 2 objects. I modified to convert the model object to array before merging.

var stream = Ember.A();
stream.pushObjects(txn.toArray());
stream.pushObjects(job.toArray());
return stream;

I also modified the property that your observing. Now Im observing the model data.

}.property('model.purchases.@each', 'model.tasks.@each'),
like image 151
blessanm86 Avatar answered Oct 01 '22 12:10

blessanm86