Skip to content

Instantly share code, notes, and snippets.

@dbouwman
Created July 25, 2016 21:12
Show Gist options
  • Save dbouwman/730481f60f11a1e53a2f05bab472bed0 to your computer and use it in GitHub Desktop.
Save dbouwman/730481f60f11a1e53a2f05bab472bed0 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
attr: {
"type":{
"label":"Type",
"fieldType":"esriFieldTypeString"
},
"date":{
"label":"Type",
"fieldType":"esriFieldTypeDate"
},
"address":{
"label":"Address",
"fieldType":"esriFieldTypeString"
}
},
mappings: {
"type":{
"field":"CRIMTYP"
},
"date":{
"field":"OCCURED_ON"
},
"address":{
"field":"ADDR"
}
},
attrJson:Ember.computed('attr',function(){
return JSON.stringify( this.get('attr'), null, 4);
}),
mappingsJson:Ember.computed('mappings',function(){
return JSON.stringify( this.get('mappings'), null, 4);
}),
merged: Ember.computed('attr',function(){
return $.extend(true, this.get('attr'), this.get('mappings') );
}),
mergedJson: Ember.computed('merged',function(){
return JSON.stringify( this.get('merged'), null, 4);
})
});
<h1>Object Merging Experiments</h1>
<h2>Attributes</h2>
<code>
<pre style="width:400px;height:250px;">{{attrJson}}</pre>
</code>
<hr>
<h2>Mappings</h2>
<code>
<pre style="width:400px;height:250px;">{{mappingsJson}}</pre>
</code>
<hr>
<br>
<h2>Merged Json</h2>
<code>
<pre style="width:400px;height:250px;">{{mergedJson}}</pre>
</code>
<hr>
<h2>Properties on Merged Object</h2>
{{#each-in merged as |key child|}}
<p>
{{key}}<br>
{{child.label}}:{{child.fieldType}}:{{child.field}}
</p>
{{/each-in}}
<br>
<br>
{
"version": "0.10.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment