ExtJs组件之间的相互访问,访问机制
<script type="text/javascript"> ????Ext.onReady(function(){ ????????????var tempWindow = new Ext.Window({ ????????????????title:"登陸", ????????????????layout:"form", ????????????????plain:true, ???????????? ? ????????????????items:[ ????????????????????{xtype:"textfield",fieldLabel:"用戶名"}, ????????????????????{xtype:"textfield",fieldLabel:"密碼"} ????????????????], ????????????????buttons:[ ????????????????????{text:"登 陸"}, ????????????????????{ ????????????????????????text:"取 消", ????????????????????????handler:function(){ ????????????????????????????alert(this.text);//這里的this是handler處理該組件的對象,可以通過this來獲得配置的相關屬性 ????????????????????????????//個人暫時的理解為this取消這個按鈕,他的父級是buttons,在父一級才是window窗口 ????????????????????????????//注意items是個屬性,并不是個數組,如果想訪問的話就必須使用itemAt來定位那個組件 ????????????????????????//??alert(this.ownerCt.ownerCt.items[0].getValue());這種寫法在ExtJs3.2中是錯誤的 ????????????????????????????alert(this.ownerCt.ownerCt.items.first().getValue());//獲得items里第一個表單中的值 ????????????????????????????alert(this.ownerCt.ownerCt.items.itemAt(1).getValue());//獲得items里第二個表單中的值 ????????????????????????????alert(this.ownerCt.ownerCt.title);//獲得window的名稱 ????????????????????????????alert(this.ownerCt.ownerCt.buttons[0].text);//獲得button中的值 ????????????????????????} ????????????????????} ????????????????] ????????????}); ????????????tempWindow.show(); ????}); </script> |
? ?
? ?
- 如果程序提供了this,那么該this是指的提供handler的對象,這里的this指的是button
- This.ownerCt組件訪問容器組件,這里可以同this.ownerCt.title可以放放window當中的屬性
- 如果想得到items對象,那么方法為:this.ownerCt.items,返回的是個集合MixedCollection,可以查看api得到更多的屬性值
- 如何獲得items當中第一個元素呢,通過this.ownerCt.items.first().getValue()方法可以獲得items里面第一個元素當中的值
? ?
問題:如何得到items當中兩個輸入框當中的內容呢?
this.ownerCt.ownerCt.items.itemAt(1).getValue()
? ?
? ?
? ?
- 方法在button當中添加一個handler通過這里的this可以獲得items,在通過items得到其中的值
- This.ownerCt.items可以獲得該上下文當中的items對象;
- 通過該對象的first()方法可以獲得姓名的表單和密碼的表單對象,通過該對象的getValue方法來獲得輸入的值
- itemsAt這個方法的起始值是從0開始的
- 直接alert(temp)就可以了
- 也可以使用Ext.getCmp()可以通過id來獲得組件對象
? ?
? ?
? ?
? ?
? ?
? ?
? ?
轉載于:https://www.cnblogs.com/babyhhcsy/p/3197839.html
總結
以上是生活随笔為你收集整理的ExtJs组件之间的相互访问,访问机制的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: u-boot的nand驱动写过程分析
- 下一篇: JS事件大全