extjs4学习之配置

最近在学习extjs4发现一篇文章中有错误,网上很多人都是直接复制粘贴那篇文章,结果每个人注释中都是写的正确的答案,我也是醉了,这些猿么复制粘贴代码都不带检查的么,为啥都变得很浮躁了呢。

现提供可以调试的代码:

html文件很简单,就引入ext资源和自定义的js文件就可以了。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试配置</title>
    <link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css">
    <script type="text/javascript" src="../../ext-all-debug-w-comments.js"></script>
    <script type="text/javascript" src="class2.js"></script>
</head>
<body>
 
</body>
</html>

js文件就是定义了2个类,一个window,一个bottomBar,其中window中包含bottomBar对象,具体代码如下:

/**
 * Created by catcher on 2016-3-30.
 */
Ext.define('My.own.Window',{
    /** @readonly */
    isWindow:true,
    config:{
        title:'This title',
        bottomBar:{
            enable:false,
            height:10,
            resizable:false
        }
    },
    constructor:function(config){
        this.initConfig(config);
        return this;
    },
    applyTitle:function(title){
        if(!Ext.isString(title)||title.length==0){
            alert("Error: Title must be a valid non-empty string!");
        }else{
            return title;
        }
    },
    applyBottomBar:function(bottomBar){
        if(bottomBar && bottomBar.enable){
            if(!this.bottomBar){
                return Ext.create('My.own.WindowBottomBar',bottomBar);
            }else{
                this.bottomBar.setConfig(bottomBar);
            }
        }
    }
});
 
Ext.define('My.own.WindowBottomBar',{
    config:{
        enable:true,
        height:10,
        resizable:false
    },
    constructor:function(config){
        this.initConfig(config);
        return this;
    }
});
 
var myWindow = Ext.create('My.own.Window', {
    title: 'Hello World',
    bottomBar: {
        enable: true,
        height: 60,
        resizable: true
    }
});
 
console.log(myWindow.getTitle()); // "Hello World"
myWindow.setTitle('Something New');
console.log(myWindow.getTitle()); // "Something New"
myWindow.setTitle(null); // alerts "Error: Title must be a valid non-empty string!"
console.log(myWindow.getBottomBar().getHeight());
myWindow.setBottomBar({enable:true,height:100}); // Bottom bar's height is changed to 100
console.log(myWindow.getBottomBar().getHeight());
    原文作者:catcher92
    原文地址: https://segmentfault.com/a/1190000007992683
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞