2012-02-28 18 views
9

我是ExtJS的新手。我开始编写一个小表格。而且我对使用Ext.create和新运算符完全感到困惑。ExtJS中的对象。 Ext.create或新运营商?

所以这里是代码:

我想编写一个表单。我在其中一个sencha页面上找到了一个小例子。它创建这样一种形式:

var descAndSystem = new Ext.form.Panel ({ 
    region: 'center', 
    layout: 'vbox', 
    margins: '5 5 5 5', 
    xtype: 'form', 
    title: 'Some title', 
    id: 'descAndSystem', 
    width: '800', 
    items: [ 
     { xtype: 'textarea', 
    fieldLabel: 'Provide a description', 
    name: 'rightdescription', 
     }, 
     { 
     xtype: 'combobox', 
     fieldLabel: 'Choose System', 
     store: systems, 
     queryMode: 'local', 
     displayField: 'name', 
     valueField: 'name', 
     name: 'system' 
     } 
    ] 
}); 

然后我用descAndSystem作为组分在视口中:

Ext.create('Ext.container.Viewport', { 
    layout: 'border', 
    id: 'wizardcontainer', 
    items: [ 
     descAndSystem, 
     { 
      region: 'south', 
      layout: 'hbox', 
      margins: '5 5 5 5', 
      items: [ 
       { xtype: 'button', text: '<< Back', handler: onNext }, 
       { xtype: 'button', text: 'Next >>', handler: onNext }, 
       { xtype: 'button', text: 'Cancel', align: 'right', handler: function() { alert ('Abgebrochen geklickt.'); } } 
      ] 
     } 
    ] 
}); 

大量的试验和错误,我发现我可以访问我的表单值后下面的代码:

Ext.getCmp ('descAndSystem').getForm().findField ('rightdescription').getValue() 

对比什么的,我买了一本书说,下面的代码没有工作:

Ext.getCmp ('rightdescription').getValue() 

但我真正的问题是,我期望

Ext.create ('Ext.form.Panel', { .... }); 

相同

new Ext.form.Panel ({...}); 

但是当我做了后者的Chrome解释说:

Uncaught TypeError: Cannot read property 'Panel' of undefined' 

再次,经过大量的反复试验,以下工作:

new Ext.Panel ({...}); 

不仅如此,我找不到文档中该名称的对象的任何引用,还行

Ext.getCmp ('descAndSystem').getForm().findField ('rightdescription').getValue() 

现在产生一个错误:

Uncaught TypeError: Object [object Object] has no method 'getForm' 

另外,我试图用DOM操作替换另一种形式的descAndSystem,文档中有各种替换方法。他们都没有工作,我总是得到错误消息“没有办法”取代“”。 我有强烈的怀疑,我从根本上弄错了什么。任何提示?我在Ubuntu 10.10 64位上使用ExtJS 4和Chromium 17.0.963.56。

+0

你一定在做错事。 Ext.create('className',{})会产生与新的className({})相同的结果。 – pllee 2012-02-29 03:26:27

回答

9

的主要区别是,Ext.create('Ext.form.Panel')会自动下载相应的javascript文件,如果Ext.form.Panel类不存在。香草new运营商无法做到这一点 - 它不知道什么Ext.form.Panel可能是或可能找到定义。

无法读取的未定义”属性“面板”错误表明不仅没有定义Ext.form.Panel,既不是父Ext.form命名空间对象。

0

更改线路

name: 'rightdescription', 

id: 'rightdescription', 

,您可以直接使用访问您的textarea:

var yourTextArea = Ext.getCmp ('rightdescription'); 
var yourTextAreaContent = yourTextArea.getValue(); 
+2

更像是“添加线条”。从表单中删除'name'不是一个好主意。 – Mchl 2012-02-29 18:07:23

+0

你是对的@Mchl。 – NTom 2012-02-29 21:50:32

0
var descAndSystem = Ext.create('Ext.form.Panel', {...}) 

这里是Ext.create()文档

至于你的其他问题...

  1. 当你说你new Ext.Panel({...})不再创建一个表单面板,因此getForm()方法将不可用。
  2. 作为@NTom表明,给任何组件的id,你将能够使用Ext.getCmp访问它。 http://docs.sencha.com/ext-js/4-0/#!/api/Ext-method-getCmp
+0

你可能拼错了'Ext.Panel',但是 - 当你说'新的Ext.from.Panel({...})'时,你创建了什么呢? – 2013-11-07 07:11:55