Note that there are some explanatory texts on larger screens.

plurals
  1. PORunning an ember controller function when route loads to set property that controls a checkbox
    text
    copied!<p>I have set up an ember checkbox:</p> <pre><code>{{view Ember.Checkbox checkedBinding='isChecked'}} </code></pre> <p>This checkbox is bound to this controller: </p> <pre><code>App.SettingsController = Ember.Controller.extend({ isChecked: false, isItChecked: function(){ var me = this; $.getJSON('ajax/checkIfUseLowRes.php', function(data){ //console.log(data); //me.isChecked = data; me.set('isChecked', data); //console.log(me.isChecked); }) }, sendSetting: function(){ var isChecked = this.isChecked; //this.set('isChecked', !isChecked); console.log(isChecked); $.post('ajax/setLowRes.php', {useLowRes: isChecked}); App.nameSpace.set('needsRefresh', true); }.observes('isChecked') }); </code></pre> <p>Essentially it is a checkbox which posts a setting, my problem is setting the original state of the checkbox. When I load the route, I want to have <code>isItChecked()</code> run to set the checkbox's original state. </p> <p>Example: 1. I go in to settings, click the checkbox 2. I leave the site and come back to the settings page Here is where I want the <code>isItChecked()</code> function to run to query the server and see if the setting is set</p> <p>If it is set, the get request returns true, I want the checkbox to be checked, hence setting me.isChecked to data (true)</p> <p>as of right now I can't figure out how to do this, can anyone help me?</p> <p>I've tried setting it in my <code>App.SettingsRoute</code>'s model, but that doesn't seem to be able to run the function in my controller.</p> <p>Thanks.</p> <p>JSBin:<a href="http://jsbin.com/ukuwiq/1/edit">http://jsbin.com/ukuwiq/1/edit</a></p>
 

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