問題:先自定義一個函數f(),在通過Ext.onReady(f())方式來調用。
看書上寫的是:
<script language="javascript">
function f(){
Ext.Msg.show({
title:'Hello',
msg:'Have you seen my heart?',
buttons:{
yes:'true',
no:true,
cancel:true,
}
});
}
Ext.onReady(f());
</script>
但運行后沒顯示
上網查了一下Ext.onReady()的用法,大概分為三種:
-
方式一:
<script>
Ext.onReady(function(){
alert('onready');
});
</script>
最簡單了,最平常的調用,不用多說
- 方式二:
<script>
Ext.color= function(){return{
init:function(){
alert("init")
}
}
}();
Ext.onReady(Ext.color.init,Ext.color);
</script>
通過onReady調用color函數,init為color中的內置,作用是初始化.這種寫法比較實用
- 方式三:
<script>
Ext.onReady(function(){
alert('onready');
});
Ext.color=function(){
return{
init:function(){
alert("init")
}
}
}();
Ext.onReady(Ext.color.init,Ext.color);
</script>
這種是混合型寫法,兩個onReady都會被調用,調用順序是看誰在前面.
根據第2個方法,可將問題的解法寫成如下:
<script>
Ext.f=function(){
return{
init:function(){
Ext.Msg.show({
title:'Hello',
msg:'Have you seen my heart?',
buttons:{
yes:true,
no:true,
cancel:true,
},
icon:'milton-icon',
fn:function(btn){
Ext.Msg.alert('You clicked',btn);
}
});
}
}
}();
Ext.onReady(Ext.f.init,Ext.f);
</script>


