控件的方法
由于BUI的控件是基于原型鏈的,所以BUI中控件的方法都是在prototype
上的哺壶,可以調(diào)用自己的或者父控件定義的方法。
控件的事件
控件的事件是由Observable類定義的至扰,所有的控件都是此類的子類资锰,所以Observable的屬性和方法,所有控件都支持台妆。
Observable類的方法的API在最下面胖翰,主要有以下幾個:
- on : 注冊事件
- off: 移除事件
- fire:觸發(fā)事件
<pre class="prettyprint linenums" style="padding: 8px; background-color: rgb(247, 247, 249); border: 1px solid rgb(225, 225, 232); margin-top: 8px; box-shadow: rgb(251, 251, 252) 40px 0px 0px inset, rgb(236, 236, 240) 41px 0px 0px inset; color: rgb(51, 51, 51); font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
<script>
var list = new List({
//...
});
list.render();
function callback(){}
//注冊事件
list.on('itemclick',callback);
//觸發(fā)事件
list.fire('itemclick');
//移除事件
list.off('itemclick',callback);
</script>
</pre>
屬性與方法和事件
在上一章節(jié)里我們詳細的講述了屬性,屬性的設置和獲取有幾個相關的方法:
- get : 獲取屬性
- set : 設置屬性萨咳,觸發(fā)屬性更改事件
- setInternal : 設置屬性,不觸發(fā)屬性更改事件
在設置屬性值時鹃两,會觸發(fā)2個事件,beforeXxxChagne 和 afterXxxChange事件
<pre class="prettyprint linenums" style="padding: 8px; background-color: rgb(247, 247, 249); border: 1px solid rgb(225, 225, 232); margin-top: 8px; box-shadow: rgb(251, 251, 252) 40px 0px 0px inset, rgb(236, 236, 240) 41px 0px 0px inset; color: rgb(51, 51, 51); font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">
<script>
//構造類A
var A = function(config){
A.superclass.constructor.call(this,config); //將自己的配置項傳遞到BUI.Base的構造函數(shù)中
};
//定義屬性
A.ATTRS = {
a : {
},
b : {
}
};
BUI.extend(A,BUI.Base); //使A繼承BUI.Base舀凛,支持屬性
var a = new A({ //創(chuàng)建對象
a : 'a',
b : 'b',
c : 'c'
});
a.on('beforeAChange',function(ev){
alert(ev.newVal + ev.prevVal);
});
a.on('beforeCChange',function(ev){
alert(ev.newVal + ev.prevVal);
});
a.get('a'); //'a'
a.set('a','new a'); //觸發(fā)beforeAChange,觸發(fā)afterAchange
a.get('a'); //new a
a.setInternal('a','new a1'); //不觸發(fā)任何事件
a.get('a'); //new a1
a.get('c'); // c
a.set('c','new c');
</script>
</pre>
事件的API
下面只是簡單的列表猛遍,詳細信息請查看API文檔