How to delete a key in emberjs?
ember.js, javascript
Solution
if you set a property on an ember object:
this.set('myObject.keyA', [1,2,3]);
it will now keep track of that key
Ember.keys('myObject'); // will show ['keyA'];
you cannot delete a key by setting it to null
this.set('myObject.keyA', null);
since
Ember.keys('myObject'); // will STILL show ['keyA'];
instead simply delete it just as a javascript object
delete this.get('myObject').keyA;
then confirm the key is gone
Ember.keys('myObject'); // will show [] an empty array;
Problem
We all know that we have `get` and `set` in ember, but how do you `delete` a key in a emberjs object? Assume an object looks like this ``` Ember.Object.create({ conf: { name: 'John', age: 16 } }); ``` During a data transport I would need to delete a key from `conf`, let's say `age`. How do you do that to correctly delete a key away from `conf`? I have tried `set('conf.age', null)` or `undefined` but seems like not working at all. EDIT A little bit of background. When I say it doesn't work for setting it undefined or null, it means it doesn't suits my need. My classes is automatically saving the `conf` data into a Mongo collection. So let's say now you have one key that is unused and you want to get rid of it, how do you remove it? Take note that there is a bigger class governing the saving process/data validation and so extending the controller just to do the deletion doesn't fit too well (ugly). And there is this `beforeSave` action that the extended class can hook on to clean up unused keys, but the problem is just that how to remove this key? It seems like such a simple action do not exist in ember, probably to deal with all sort of binding/observers..