我需要将子视图绑定到父视图的视图模型。我的结构是 -
parentView{
items : [{
xtype : 'childview'
}]
}
parentViewModel{data : NAME}
childview : {
items : {[
xtype : 'label',
bind : {value : '{NAME}'}
]}
}
我需要将子视图绑定到父视图的视图模型。我的结构是 -
parentView{
items : [{
xtype : 'childview'
}]
}
parentViewModel{data : NAME}
childview : {
items : {[
xtype : 'label',
bind : {value : '{NAME}'}
]}
}
实际上,您根本不需要viewModel
为孩子使用。组件链中的所有子视图都可以自然地访问父视图viewModel
。
Ext.define('APP.view.Main', {
extend: 'Ext.panel.Panel',
alias: 'widget.main',
viewModel: {
data: {
title: 'TITLE',
name: 'NAME'
}
},
bind: { title: '{title}' },
items: [{ xtype: 'child' }]
});
Ext.define('APP.view.Child', {
extend: 'Ext.container.Container',
alias: 'widget.child',
items: [{
xtype: 'label',
bind: { value: '{name}' }
}]
});
更多解释请参见ExtJS 指南。(我真诚地建议阅读所有内容:))。
希望这有所帮助!
好的,对于初学者来说,你的绑定语法是错误的,如果你不需要'label' xtype 作为表单,你也可以使用更轻的 component.html。
parentViewModel: {
data: {
name: 'Igor'
}
}
xtype: 'component',
bind: {
html: '{name}'
}