2013-12-12 52 views
0

以下代碼似乎更改了文本字段值,因爲AFTER警報顯示值已更改。在Extjs 4.2中爲什麼setValue()不更新文本字段?

但是當你看看錶單中的文本框時,它是空白的?

var selectedItem = JSON.parse(CommonUtil.getSelectedRows(this.getSettingGrid()))[0]; 
alert("BEFORE: " + this.getSettingVcenter().queryById('txtName').getValue()); 
this.getSettingVcenter().queryById('txtName').setValue(selectedItem.name); 
alert("AFTER: " + this.getSettingVcenter().queryById('txtName').getValue()); 
+0

this.getSettingVcenter()返回什麼? –

回答

1

我能想到的唯一原因是可能的是您不修改實際的文本字段,而是修改對象或其他內容的副本。

爲了獲取在內線的組件,你應該使用:

var myTextField = Ext.ComponentQuery.query('textfield[itemId=someId]')[0]; 

myTextField.setValue("newValue"); //This is guaranteed to work 

還可以使用:

console.log(yourObject); //this is to see the xtype of what your are modyfing the value, is it really the textfield?` 

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.ComponentQuery-method-query

0

使文本框可見通過使用setter方法setVisible(true)設置後價值,讓它顯示出來。我試過用mytextField.hidden=false;但在事後不起作用。

+0

它看起來像[幾乎類似於你的答案](http://stackoverflow.com/a/20550509/2343633)幾個月前發佈,但從來沒有例外。你的答案不同嗎? – rbatt

相關問題