Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://builds.emberjs.com.s3.amazonaws.com/tags/v1.0.0/ember.js"></script>
  <script src="http://builds.emberjs.com/beta/ember-data.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <script type="text/x-handlebars">
 
    {{#each possibleValues}}
        <label>{{this.label}}</label>
        {{input type="checkbox" checked=this.isChecked}}<br>
    {{/each}}
    <button {{action save}}>save</button>
    {{collected}}
    </script>
</body>
</html>
 
App = Ember.Application.create();
App.ApplicationAdapter = DS.RESTAdapter.extend();
App.ApplicationController = Ember.ObjectController.extend({
  init: function () {
    this._super();
    var user = this.store.createRecord('user');
    this.set('content', user);
  },
  actions:{
    save: function () {
      var user = this.get('content'),
          collected = user.get('classifications');
      this.set('collected', collected);
      user.save();
      
     }
  },
  //executes when isChecked is changed in one item of possibleValues
  collectChecked: function () {
    var classifications;
    classifications = this.get('possibleValues').filterBy('isChecked', true); //filter checked only 
    classifications = classifications.mapBy('value'); //map values
    this.set('classifications', classifications);
    console.log(classifications);
  }.observes('possibleValues.@each.isChecked'),
  possibleValues: [{
    label: 'Label for value 1',
    isChecked: false,
    value: 'Value 1'
  },{
    label: 'Label for value 2',
    isChecked: false,
    value: 'Value 2'
  },{
    label: 'Label for value 3',
    isChecked: false,
    value: 'Value 3'
  }]
});
App.RawTransform = DS.Transform.extend({
  deserialize: function(serialized) {
    return serialized;
  },
  serialize: function(deserialized) {
    return deserialized;
  }
});
App.User = DS.Model.extend({
  classifications: DS.attr('raw')
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers