EmberJS 对象模型声明观察器
11-27
EmberJS 对象模型声明观察器
不带原型扩展
使⽤不带原型扩展的Ember.observer ⽅法定义内联观察器。
语句
App.ClassName = Ember.Object.extend({
ComputedPropertyName: Ember.observer('ComputedPropertyNames', //do the stuff
})
});
类定义之外
使⽤addObserver 将观察器添加到类定义之外的对象
语句
ClassName.addObserver('ComputedPropertyNames', function(){ //do the stuff
});
例⼦
Emberjs Declaring the Observer
Output 让我们执⾏以下步骤,看看上⾯的代码如何⼯作:
将上⾯的代码保存在obj_obsrvr_declr.html⽂件中
在浏览器中打开此HTML ⽂件。
W3Cschool (www.w3cschool.cn )最⼤的技术知识分享与学习平台
此篇内容来⾃于w3cschool.cn ⽹站⽤户上传并发布。