您好,登錄后才能下訂單哦!
筆記:
1.JS 類聲明,和對象的創建
2.原型方法用EXTJS創建一個window
3.利用一個按鈕觸發window窗體,了解一下EXTJS的事件機制
4.用EXTJS4.0的create來創建window
5.利用define自定義類并且繼承(extend)window
//初始化的方法 構造器
initComponent:function(){
this.callParent(arguments);
}
6.requires JS的異步加載
7.config 自動的get和set
8.mixins 類的混合
---------------------------------------------------------------------------------
這個例子主要講類的私有屬性和公有屬性
lesson02.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>HELLO WORD</title>
- <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/>
- <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script>
- <script type="text/javascript" src="indexDemo.js"></script>
- </head>
- <body>
- </body>
- </html>
indexDemo.js
- //類的聲明其實就是一個function
- function user(){
- //java 語言的public
- this.Name = 'uspcat';
- this.age = 26;
- //var 就相當于高級語言中的private
- var email = "yfc@126.com";
- this.getEmail = function(){
- return email;
- }
- }
- var u = new user();
- alert(u.Name);
- alert(u.email);
- alert(u.getEmail());
- var person = {
- name:'yfc',
- age:26
- };
- alert(person.name + " " + person['age']);
------------------------------------------------
這個例子主要講如何使用創建Ext.window.Window,可以使用show方法顯示窗口,
lesson02.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Ext.window.Window</title>
- <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/>
- <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script>
- <script type="text/javascript" src="indexDemo2.js"></script>
- </head>
- <body>
- </body>
- </html>
indexDemo2.js
- (function(){
- Ext.onReady(function(){
- var win = new Ext.window.Window({
- width:400,
- height:300,
- title:'uspcat'
- });
- win.show();
- });
- })();
------------------------------------------------------------------
這個例子主要將Extjs如何使用Ext.get(獲取指定id的頁面元素)和事件
lesson02_02.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Ext.window.Window</title>
- <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/>
- <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script>
- <script type="text/javascript" src="indexDemo2.js"></script>
- </head>
- <body>
- <button id="myb">Show</button>
- </body>
- </html>
indexDemo3.js
- (function(){
- Ext.onReady(function(){
- var win = new Ext.window.Window({
- width:400,
- height:300,
- title:'uspcat',
- closeAction:false//如果沒有設置,關閉之后第二次win.show()將會報el is null el.addCls.apply(el,
- arguments);
- });
- //1.得到那個按鈕的dom對象
- //2.為按鈕對象添加單擊的事件
- //3.單擊的時候調用對象win的show方法
- Ext.get("myb").on("click",function(){
- win.show();
- },this);
- });
- })();
----------------------------------------------------------------------------------
這個例子主要講Ext.Function.alias如何創建對象方法的別名
lesson02_03.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>別名</title>
- <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/>
- <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script>
- <script type="text/javascript" src="indexDemo4.js"></script>
- </head>
- <body>
- </body>
- </html>
indexDemo4.js
- (function(){
- Ext.onReady(function(){
- var o = {
- say : function(){
- alert(111);
- }
- }
- var fn = Ext.Function.alias(o,'say');
- fn();
- });
- })();
------------------------------------------------------------------------------
這個例子主要將如何使用Ext.create創建對象
lesson02_04.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Ext.create</title>
- <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/>
- <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script>
- <script type="text/javascript" src="indexDemo5.js"></script>
- </head>
- <body>
- </body>
- </html>
indexDemo5.js
- (function(){
- Ext.onReady(function(){
- var win = Ext.create('Ext.window.Window',{
- width:400,
- height:300,
- title:'uspcat'
- });
- win.show();
- });
- })();
--------------------------------------------------------------
這個例子主要講Ext.define方法和initComponent屬性,initComponent在創建類的對象的時候最自動調用,相當于java的構造器,另外還講了callParent方法
lesson02_06.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Ext.create</title>
- <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/>
- <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script>
- <script type="text/javascript" src="indexDemo6.js"></script>
- </head>
- <body>
- </body>
- </html>
indexDemo6.js
- (function(){
- Ext.onReady(function(){
- Ext.define("myWin",{
- extend:'Ext.window.Window',
- width:400,
- height:300,
- title:'uspcat',
- newtitle:'new uspcat',
- mySetTitle:function(){
- this.title = this.newtitle;
- },
- initComponent: function(){
- this.mySetTitle();
- this.callParent(arguments);
- }
- });
- Ext.create('myWin',{
- title:'my win'
- }).show();
- });
- })();
initComponent方法會自動調用
----------------------------------------------------------------------------------
這個例子主要講如何引入js文件
ux\mywin.js
- Ext.define("myWin",{
- extend:'Ext.window.Window',
- width:400,
- height:300,
- title:'uspcat',
- newtitle:'new uspcat',
- mySetTitle:function(){
- this.title = this.newtitle;
- },
- initComponent: function(){
- this.mySetTitle();
- this.callParent(arguments);
- }
- });
lesson02_06.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Ext.create</title>
- <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/>
- <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script>
- <script type="text/javascript" src="indexDemo6.js"></script>
- <script type="text/javascript" src="ux/mywin.js"></script>
- </head>
- <body>
- </body>
- </html>
indexDemo6.js
- (function(){
- Ext.onReady(function(){
- Ext.create('myWin',{
- title:'my win'
- }).show();
- });
- })();
--------------------------------------------------------------------------------------
這個例子是需要服務器啟動的時候才能正常運行的,有兩個地方需要注意:
第一個是
- Ext.Loader.setConfig({
- enabled:true,
- paths:{
- myApp:'lessonTwo/ux'//什么位置都沒有關系
- }
- );
另一個是類名,必須是在當前文件夾下的文件下面的js文件才能夠動態加載,而且類名必須是當前文件夾下的文件名加上js文件名
indexDemo7.js
- (function(){
- Ext.Loader.setConfig({
- enabled:true,
- paths:{
- myApp:'lessonTwo/ux'//什么位置都沒有關系
- }
- });
- Ext.onReady(function(){
- Ext.create('ux.myWin2',{//在ux/myWin2下的ux.myWin2類
- title:'my win',
- //requires:['myWin']
- }).show();
- });
- )();
lesson02_07.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Ext.create</title>
- <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/>
- <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script>
- <script type="text/javascript" src="indexDemo7.js"></script>
- </head>
- <body>
- </body>
- </html>
ux\myWin2.js
- Ext.define("ux.myWin2",{
- extend:'Ext.window.Window',
- width:400,
- height:300,
- title:'uspcat',
- newtitle:'new uspcat',
- mySetTitle:function(){
- this.title = this.newtitle;
- },
- initComponent: function(){
- this.mySetTitle();
- this.callParent(arguments);
- }
- });
----------------------------------------------------------------------------------
這個例子主要是顯示 當點擊按鈕之后myWin2.js這個js文件是動態加載
lesson02_08.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Ext.create</title>
- <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/>
- <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script>
- <script type="text/javascript" src="indexDemo8.js"></script>
- </head>
- <body>
- <button id="myb">Show</button>
- </body>
- </html>
indexDemo8.js
- (function(){
- Ext.Loader.setConfig({
- enabled:true,
- paths:{
- myApp:'lessonTwo/ux'//什么位置都沒有關系
- }
- });
- Ext.onReady(function(){
- Ext.get("myb").on("click",function(){
- Ext.create('ux.myWin2',{//在ux/myWin2下的ux.myWin2類
- title:'my win',
- //requires:['myWin']
- }).show();
- });
- });
- )();
ux\myWin2.js
- Ext.define("ux.myWin2",{
- extend:'Ext.window.Window',
- width:400,
- height:300,
- title:'uspcat',
- newtitle:'new uspcat',
- mySetTitle:function(){
- this.title = this.newtitle;
- },
- initComponent: function(){
- this.mySetTitle();
- this.callParent(arguments);
- }
- });
-------------------------------------------------------------------------------------
這個例子主要是講Ext.define中config屬性,配置了之后就會自動有getPropertyName方法了
lesson02_09.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Ext.create</title>
- <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/>
- <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script>
- <script type="text/javascript" src="indexDemo9.js"></script>
- </head>
- <body>
- <button id="myb">Show</button>
- </body>
- </html>
indexDemo9.js
- (function(){
- Ext.Loader.setConfig({
- enabled:true,
- paths:{
- myApp:'lessonTwo/ux'//什么位置都沒有關系
- }
- });
- Ext.onReady(function(){
- Ext.get("myb").on("click",function(){
- var win = Ext.create('ux.myWin3',{//在ux/myWin2下的ux.myWin2類
- title:'my win',
- price:60
- });
- alert(win.getPrice());
- win.show();
- });
- });
- )();
ux\myWin3.js
- Ext.define("ux.myWin3",{
- extend:'Ext.window.Window',
- width:400,
- height:300,
- config:{
- price:500
- },
- title:'uspcat',
- newtitle:'new uspcat',
- mySetTitle:function(){
- this.title = this.newtitle;
- },
- initComponent: function(){
- this.mySetTitle();
- this.callParent(arguments);
- }
- });
----------------------------------------------------------------------------------
最后一個例子主要是講Ext.define的mixins屬性,其實跟js的實例繼承法很類似
lesson02_10.html
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Ext.create</title>
- <link rel="stylesheet" type="text/css" href="../extjs-4.1.0/resources/css/ext-all.css"/>
- <script type="text/javascript" src="../extjs-4.1.0/bootstrap.js"></script>
- <script type="text/javascript" src="indexDemo10.js"></script>
- </head>
- <body>
- </body>
- </html>
indexDemo10.js
- (function(){
- Ext.onReady(function(){
- Ext.define('say',{
- cansay:function(){
- alert("hello");
- }
- });
- Ext.define('sing',{
- sing:function(){
- alert('sing hello 123');
- }
- });
- Ext.define('user',{
- extend:'sing',//繼承只能繼承一個類
- mixins:{
- say:'say'//這個say類的say對象
- }
- });
- var u = Ext.create('user',{});
- u.cansay();
- u.sing();
- });
- })();
11
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。