2017-08-09 54 views
1

我试图从viewcontroller禁用在filefield的运行时禁用按钮,但我得到的错误。EXTJS 6.0.2 - 禁用文件字段按钮不起作用

错误Component.js

me.ariaEl.dom.setAttribute( '咏叹调禁用',假); //无法读取空的特性 '的setAttribute'[似乎me.ariaEl.domis来为空]

错误堆栈跟踪.........

Uncaught TypeError: Cannot read property 'setAttribute' of null 
at constructor.onEnable (Component.js?version=20170809094755:4378) 
at constructor.callParent (Base.js?version=20170809094755:1288) 
at constructor.onEnable (Button.js?version=20170809094755:1786) 
at constructor.callParent (Base.js?version=20170809094755:1288) 
at constructor.onEnable (FileButton.js?version=20170809094755:165) 
at constructor.enable (Component.js?version=20170809094755:3033) 
at constructor.setDisabled (Component.js?version=20170809094755:4863) 

我有一个简单文件中的字段,

  { 
       xtype: 'filefield', 
       fieldLabel: 'Attach Items', 
       buttonText: 'Browse Items', 
       itemId : 'buttonid', 
       buttonConfig: { 
        id : 'uploadmailwidget0Btn' 


       }, 
      } 

试图在视图控制器为禁用 - 代码:

Ext.getCmp('uploadmailwidget0Btn').setDisabled(true); 

有人可以帮忙吗?问很简单,我想从viewcontroller禁用filefield上的按钮。

+0

您正在使用哪个版本的ExtJS? –

+0

在6.0.2上工作 – Gendaful

+0

你可以试试.disable()方法的文件上传组件。如果它不起作用,可以回复。或者你可以创建一些sencha小提琴 – Tejas

回答

1

我认为你想要做的是在你的ViewController中使用lookup

您需要添加一个引用到按钮

{ 
    xtype: 'filefield', 
    fieldLabel: 'Attach Items', 
    buttonText: 'Browse Items', 
    itemId : 'buttonid', 
    buttonConfig: { 
    id : 'uploadmailwidget0Btn', 
    }, 
    reference: 'myButtonRef' 
}, 

,并使用该引用的视图控制器使用lookup并更改禁用值。

function() { 
    this.lookup('myButtonRef').setDisabled(true); 
    } 

当然,我没有使用ExtJS的不多,但在理论上这应该工作

+0

我能够得到按钮的句柄。但我正在尝试使用button.setDisabled方法禁用按钮时出现错误。即使绑定的残疾人:'{旗}'没有帮助禁用按钮 – Gendaful

1

正如ExtJS 6 documentation所示,setDisabled方法是私有的,所以它是不可访问。

但是,我们可以做这样的事情。请记住,这个解决方案并不聪明,但它的工作原理。 测试example fiddle

Ext.application({ 
    name : 'Fiddle', 
    launch : function() { 
     Ext.create('Ext.window.Window', { 
      title: 'Hello', 
      height: 200, 
      width: 400, 
      layout: 'fit', 
      items: [{ 
       xtype: 'filefield', 
       id: 'fileid', 
       fieldLabel: 'Attach Items', 
       buttonText: 'Browse Items', 
       itemId: 'buttonid', 
       buttonConfig: { 
        id: 'uploadmailwidget0Btn' 
       } 
      }, { 
       xtype: 'button', 
       text: 'Click to set disable', 
       handler : myBtnHandler 
      }] 
     }).show(); 

    } 
}); 

var myBtnHandler = function(btn) { 

    if (Ext.getCmp('fileid').bodyElement.dom.childNodes[0].childNodes[2].childNodes[1].childNodes[0].childNodes[2].disabled) 
    { 
     btn.setText('Click to set disable'); 
     Ext.getCmp('fileid').bodyElement.dom.childNodes[0].childNodes[2].childNodes[1].childNodes[0].childNodes[2].disabled = false; 
    } 
    else 
    { 
     btn.setText('Click to set enable'); 
     Ext.getCmp('fileid').bodyElement.dom.childNodes[0].childNodes[2].childNodes[1].childNodes[0].childNodes[2].disabled = true; 
    } 
} 
+0

我真的无能为力导致这个错误。禁用(或设置为隐藏)应该工作正常,但当文件元素更改其状态时,会抛出错误。我试图禁用使用viewmodel/setDisabled /和comp.disabled = false的方式,但错误保持不变。最后,我不去改变状态,而是将新组件添加到容器中。这工作:) – Gendaful