Ember 1.5 How to combine two arrays of records?

In my application I have a feed. Let's just say that these two elements are Tasks and Purchases.

In my channel, I want both of these elements to fill an array sorted by date. They have the same properties, such as name and date. As for displaying them in the user interface, I have no doubt that I can understand this.

The problem is getting the records.

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

Both of these arrays return a promise. I assume that I will need some kind of proxy server. But my current code will not update the array every time the property changes to an object in any of these arrays. And it will also not display correctly or change when objects are added to these stores.

Did anyone manage to combine two arrays of records into one? And if it functions as if it were only one array of records, which is updated on the fly perfectly with each exchange with the array and objects inside.

Any help appreciated! If you need more code, I will post a message!

UPDATE ::

Attached is JSBIN, which should display what I'm trying to do and the fact that it does not work.

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

+4
source share
2 answers

Here is your script modified .

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

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

, . Im .

}.property('model.purchases.@each', 'model.tasks.@each'),
+7

, , :

App.YourRoute = Em.Route.extend({  
  model: function(params) {
    return Em.RSVP.hash({
      tasks:     this.store.find('task'),
      purchases: this.store.find('purchase')
    });
 },

<script type="text/x-handlebars" data-template-name="index">
  <h2>Tasks:</h2>
  <ul>
    {{#each tasks}}
      <li>{{title}}</li>
    {{/each}}
  </ul>
  <h2>Purchases:</h2>
  <ul>
    {{#each purchases}}
      <li>{{title}}</li>
    {{/each}}
  </ul>
</script>
0

Source: https://habr.com/ru/post/1538960/


All Articles