让我们说我有Ember模型对象:
App.ModelObject = Ember.Object.extend({
attribute1: null,
attribute2: 0,
attribute3: "",
init: function(){
var self = this;
self._super();
console.log(Ember.keys(self).length);
}
});
var obj = App.ModelObject.create(); //logs to console "0"
比这更发生了(我认为这是不受欢迎的):
Ember.keys(obj).length; // === 0
obj.set("attribute1", 1);
Ember.keys(obj).length; // === 1
obj.set("attribute1", null);
Ember.keys(obj).length; // === 1
obj.set("attribute2", 0);
Ember.keys(obj).length; // === 1
obj.set("attribute2", null);
Ember.keys(obj).length; // === 2
如果我想获取模型的所有键(属性),我必须做什么,所以它应该返回["attribute1", "attribute2", "attribute3"]
?