Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber.js "Each" trouble
    primarykey
    data
    text
    <p>In Ember.js I have this model:</p> <pre><code>App.Product = DS.Model.extend({ name: DS.attr("string"), ean: DS.attr("number"), price: DS.attr("number"), units: DS.attr("number"), product_states: DS.hasMany('App.ProductState') }); App.ProductState = DS.Model.extend({ price: DS.attr("number"), units: DS.attr("number"), product_id: DS.belongsTo('App.Product'), user_id: DS.belongsTo('App.User'), created: DS.attr("date") }); </code></pre> <p>And I have this each:</p> <pre><code> {{#if view.product}} {{#each item in App.ProductState.find({ product_id: view.product.id})}} &lt;tr&gt; &lt;td&gt;{{view.product.name}}&lt;/td&gt; &lt;td&gt;{{item.price}}&lt;/td&gt; &lt;td&gt;{{item.units}}&lt;/td&gt; &lt;td&gt;{{item.created}}&lt;/td&gt; &lt;/tr&gt; {{/each}} {{/if}} </code></pre> <p>Which gives me this error (Chrome):</p> <pre><code>Uncaught Error: Parse error on line 6: ...in App.ProductState.find({ product_id: v -----------------------^ Expecting 'ID', got 'INVALID' </code></pre> <p>I get this error when I am loading the page. In the time of loading the view.product is set to NULL. The each is inside of jQuery UI dialogue and its content is set dynamically as a result of button through <code>view.set("product",product);</code>.</p> <p>Setting the product object works because when I want to just print out a product variable in the dialogue window it works just fine but it crashes when I am using the each.</p> <p>In my opinion Ember ignores the if condition and tries to run through the each cycle which gives the error. Other option is that I am just using the find method wrong (btw. Ember guide tells you how to set model relationships but as far as I know does not mention what effect they have and how to use them properly).</p> <p>Is it possible to work around the problem? Maybe something like running the each in javascript function instead of template or something?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload