vendredi 14 février 2020

How do I render the values returned from a computed property in Ember.js?

I have the following code in the template of my component:

      <th scope="row"></th>
      <td>Name: 
      </td>
      <td>Delivery address: 
          Products in order: 
          Items: 
      <td>$</td>
</tr>

And I have my computed property which should return and render each product name in the array of objects returned from the database:

items: computed('order.products', function() {
        let products = this.get('order.products');
        products.forEach(product => {
            for(let i=0; i<products.length; i++){
                return console.log(products[i].name);
            }
        });
    }),

And when I run the following everything works okay and the names are displayed in the console like this:

Cheese on toast
3 Pizza
2 Macaroons bowl

But when I try to remove console.log and just return products[i].name, nothing seems to be returned. Am I missing something or trying to render it on my page incorrectly?




Aucun commentaire:

Enregistrer un commentaire