Created
January 25, 2017 20:13
-
-
Save k-fish/bcdf7bcbe044ef668b3d09d2db77a1c9 to your computer and use it in GitHub Desktop.
Reflexive Rebinding Example (Push/Remove Object)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
actions: { | |
moveFolder(folder, currentParent) { | |
const newParent = this.get('model.parentFolders').rejectBy('name', currentParent.get('name'))[0]; | |
console.log(newParent); | |
folder.set('parent', newParent); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
import DS from 'ember-data'; | |
export default Model.extend({ | |
name: attr('string'), | |
parent: belongsTo('folder', { inverse: 'children' }), | |
children: hasMany('folder', { inverse: 'parent' }) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
const parentOne = this.store.createRecord('folder', { | |
name: 'Parent One' | |
}); | |
const parentTwo = this.store.createRecord('folder', { | |
name: 'Parent Two' | |
}); | |
const childOne = this.store.createRecord('folder', { | |
name: 'Child One', | |
parent: parentOne | |
}); | |
const childTwo = this.store.createRecord('folder', { | |
name: 'Child Two', | |
parent: parentOne | |
}); | |
const childThree = this.store.createRecord('folder', { | |
name: 'Child Three', | |
parent: parentOne | |
}); | |
const childFour = this.store.createRecord('folder', { | |
name: 'Child Four', | |
parent: parentOne | |
}); | |
const parentFolders = [parentOne, parentTwo]; | |
return { | |
parentFolders | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.11.0", | |
"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.10.2", | |
"ember-data": "2.11.0", | |
"ember-template-compiler": "2.10.2", | |
"ember-testing": "2.10.2" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment