Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber Getting property from Controller in Model
    primarykey
    data
    text
    <p>I have a computed property on a model and in order to compute that I need a property from a controller (not the one that is controlling the model). I know there is <code>needs:</code> but this is just on<br> a controller level.<br> How could I get a property in Ember from a controller other than the one that is managing the model? </p> <p>I'm trying to do some formatting like the person that [asked this question][1] but I didn't succeed what has been suggested there.<br> So I try to do the formatting on the model with a computed property, but to calculate that property I need another property from a controller.</p> <p>Any help is greatly appreciated! Thanks!</p> <p>Note: I'm using EmberData to manage the model.</p> <p><strong>Edit:</strong><br> In order to clarify what I'm trying to do I have set up an example that shows the problem<br> in a <em>general</em> way: The example application lets you input numbers, store them,<br> and show them in a list. You can also input a "conversion factor" which doesn't change the model data itself but the presentation on the template. Say, you input the number 2, 2 gets saved on the model but when it is shown in the list it gets "formatted" with the conversion factor you entered previously and the calculated value is shown in the template. The problem is that the value with which I want to format is stored on a different controller. Here's what I have tried so far: </p> <ul> <li><p><strong>#1 Approach:</strong><br> Computed Property on the ArrayController - using <code>needs:</code> in the controller to traverse and get the value<br> --><a href="http://jsfiddle.net/Nairam/ZEfRg/">jsfiddle</a><br> <strong>Problems I have encountered:</strong><br> The ArrayController seems to break and the template renders as if there are no stored records at all (Note: the example uses local storage, so create some records and uncomment the computed property on the ArrayController and you'll see it works originally as expected and shows the records you entered). </p></li> <li><p><strong>#2 Approach:</strong><br> Computed Property on model itself<br> --><a href="http://jsfiddle.net/Nairam/4aARv/">jsfiddle</a><br> <strong>Problems I have encountered:</strong><br> I have no idea how I can get a property from a controller while beeing inside the model </p></li> <li><strong>#3 Approach:</strong><br> Handlebars Helper and <code>needs:</code> on the controller<br> 1) Define a computed property on the controller (that handles the model) to get the value in question from the other controller<br> 2) create a handlebars helper and pass in the value from the model and the value from the controller and return the calculated value<br> -->jsfiddle (You can find the link for the 3rd jsfiddle in the comments since I don't have enough reputation points yet).<br> <strong>Problems I have encountered:</strong><br> Instead of displaying the formatted number I get "NaN" on every value in the rendered template. </li> </ul> <p>If anyone has an idea how to solve this or can point me into the right direction would be great. Your help is really appreciated! Thanks for your time! </p>
    singulars
    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.
 

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