在EXT官方网站,有这样一个例子,生成一个登录框,代码如下:xt.onReady(function(){
    Ext.QuickTips.init();
    
 
// Create a variable to hold our EXT Form Panel. 
// Assign various config options as seen.  
    var login = new Ext.FormPanel({ 
        labelWidth:80,
        url:'Login.jsp', 
        frame:true, 
        title:'Please enter your name', 
        defaultType:'textfield',
monitorValid:true,
........................................................defaultType这个configur在API的解释是:
The default xtype of child Components to create in this Container when a child item is specified as a raw configuration object, rather than as an instantiated Component.Defaults to 'panel'.
默认值是panel,那么'textfield'又是哪个组件的呢,查查API吧
textfield        Ext.form.TextField这就很奇特了,按照对XTYPE的解释:。XType配置项代表着这个对象属于哪个组件类型,而到时(渲染时)就会调用相关的构造器(constructor)。整个过程无须手工调控,均由ComponentMgr对象内部控制。总得来说,用字面化对象(object literal)的方式定义了一个组件实例的功能,不失为一种便捷的做法(handy shortcut)。 
login 这个变量是Ext.FormPanel类,而渲染时又按照Ext.form.TextField来渲染(因为它注册的XTYPE是textfield ),那么这个到底是怎么回事呢?login到底是个Ext.FormPanel类的实例,还是Ext.form.TextField类的实例呢?

解决方案 »

  1.   

    试试改成:defaultType:Ext.form.TextField 
      

  2.   

    帅哥,你帮助没看完。
    defaultType : String
    The default xtype of child Components to create in this Container when a child item is specified as a raw configurati...The default xtype of child Components to create in this Container when a child item is specified as a raw configuration object, rather than as an instantiated Component.This usually defaults to 'panel', but for Ext.form.FormPanel and Ext.form.FieldSet, the defaultType is 'textfield'.
    var login = new Ext.FormPanel
    毫无疑问,login是formpanel的实例
    defaultType定义的是子元素类型
    例:new Ext.FormPanel({
      defaultType:'textfield',
      items:[componentconfig,...]
    })
    如果componentconfig未定义xtype,则应用defaultType之定义
      

  3.   

    感谢2楼的,我重新查询了API DOC ,官方网站http://extjs.com/deploy/dev/docs/,我可以非常确定地说,我没有看错,的确是
    defaultType : String
    The default xtype of child Components to create in this Container when a child item is specified as a raw configurati...The default xtype of child Components to create in this Container when a child item is specified as a raw configuration object, rather than as an instantiated Component.Defaults to 'panel'.可能因为官方的是2.2.1,你看的还是ext1.x的版本,所以我们看到的不一样而且,如果我把default:.......这行注释掉,那么输入框就出不来,和我使用default:panel的效果是一样的。说明ext2 的确已经将这个default修改成panel不过你帮助我搞清楚了DefaultType的真正含义——定义后面item的类,而不是定义本身的类,非常感谢
      

  4.   

    我觉得defaultType 就是定义panel面板中的元素的属性 ,这个方法是为了简便 ,比如说大多数都是textfield属性 ,然后个别的在自己里面定义xtype属性就可以了,这样不用每个都 xtype 我也刚学不知道有没说错