我有两个组件:一个面板和一个自定义文本框。
面板有一个视图模型,我想将该视图模型中的一个值(称为
基本上这样可以正常工作,但是当文本框的
我不确定我做错了什么,但是这是我迄今为止尝试过的:https://fiddle.sencha.com/#fiddle/20pu&view/editor
面板有一个视图模型,我想将该视图模型中的一个值(称为
testData
)绑定到自定义文本框的属性(称为test
)。基本上这样可以正常工作,但是当文本框的
test
属性更改时,面板的视图模型中的testData
没有相应地更新。我的意思是,当子元素(文本框)的test
属性被修改时,面板的视图模型中的testData
属性应该包含与test
相同的值,就像普通的双向绑定一样。我不确定我做错了什么,但是这是我迄今为止尝试过的:https://fiddle.sencha.com/#fiddle/20pu&view/editor
Ext.define('MyMain', {
extend: 'Ext.panel.Panel',
alias: 'widget.main',
width: '100%',
bodyPadding: 10,
viewModel: {
data: {
testData: 'Example Data'
}
},
bind: {
title: '{testData}'
},
items: {
xtype: 'myField',
bind: {
test: '{testData}'
}
}
})
Ext.define('MyField', {
extend: 'Ext.form.field.Text',
alias: 'widget.myField',
fieldLabel: 'Data',
width: '100%',
config: {
test: null // when test is changed, it should also affect the {testData} bind of the main component, causing the title to change
},
setTest(value) {
this.test = value + ' modified!' // because of the bind, this /should/ automatically get appied to the viewmodel's `testData` and thus to the panel title
this.setValue(this.test) // whenever the `test` property is changed, we write the contents to the value of the text field (just to visualize the `test` property).
// But as you can see, the panel title will still just say `Example Data` and not `Example Data modified!` as it should.
},
getTest(){
return this.test
}
})
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.create('Ext.container.Viewport', {
items: [{
xtype: 'main'
}]
})
}
})
config
作为默认值存在,您可以使用参数test
创建组件,该参数将覆盖test
中的默认值。 - Edwintest
的内容,只有一个名为testData
的内容。 - Edwin