gokatz
4/27/2016 - 5:28 AM

array map

array map

{
  "version": "0.7.2",
  "EmberENV": {
    "FEATURES": {}
  },
  "options": {
    "use_pods": false,
    "enable-testing": false
  },
  "dependencies": {
    "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
    "ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember.debug.js",
    "ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
    "ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js"
  }
}
<h1>Welcome to {{appName}}</h1>
<br>
<button {{action 'constructArray'}}>constructArray</button>
<br>
{{#each test as |obj|}}
  	{{obj.a}}
    {{obj.b}}
    {{obj.name}}<br>
{{/each}}
<hr>
<button {{action 'setob'}}>set</button>
<br>
{{#each bb as |arrlist|}}
	{{#each arrlist as |entry|}}
  	{{entry.a}}
    {{entry.b}} |
  {{/each}}
  <br>
{{/each}}

<br><br>
{{#each arr as |entry|}}
	{{my-component entry=entry}}
{{/each}}
<br>
{{outlet}}
<br>
<br>
body {
  margin: 12px 16px;
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 12pt;
}

.test {
  display: inline-block;
  border: 1px solid red; 
  width: 50px;
}
import Ember from 'ember';

export default Ember.Controller.extend({
  appName: 'Ember Twiddle',
  arr: [1,2,3,4],
  bb : Ember.A([[{a:1, b:2},{a:3,b:4},{a:5,b:6}],[{a:1, b:2},{a:3,b:4},{a:5,b:6}],[{a:1, b:2},{a:3,b:4},{a:5,b:6}]]),
  test: [{a:1, b:2},{a:3,b:4},{a:5,b:6}],
  
  v : {l1:[{a:1,b:2},{a:3, b:4}],
      l2:[{a:1,b:2},{a:3, b:4}],
      l3:[{a:1,b:2},{a:3, b:4}]},
  
  cc : Ember.computed(function() { 
  	var arr = this.get('bb');
    return arr[0][0].a;
  }),
  
  actions: {
		domap() {
  		var barr = this.get('bb');
  		barr.map((item, index) => {
        alert(item);
				return item+1;
			})
      console.log(barr);
		},
    
    setob() {
    	var arr = this.get('bb');
      var d = arr[0][0];
      console.log(d.a);
    	d.set('a', 10);
    },
    
    sete() {
    	var t = this.get('test');
      t.setEach('name', 'gokul');
    },
    
    constructArray() {
    	var tt = this.get('v');
      console.log(tt);
      var array =[];
      for(var key in tt) {
      	array.pushObject(tt[key]);
      }
      console.log(array);
    }
	}
});
import Ember from 'ember';

export default Ember.Component.extend({
  classNames: ['test'],
});