也许任何人都可以帮我解决我的简单问题:使用itemtap我创建一个模态面板。此模态面板具有文本字段。我想将点击的项目绑定到新面板的文本字段。我在监听器函数中使用'Ext.create ...'来创建面板。如何将记录现在传递到我希望在viewModel中使用它的面板?
注意评论! :-)
这是我的Main.js,带有一个网格和一个itemtap监听器。这里的记录来自:
Ext.define('QuickApp.view.main.Main', {
extend: 'Ext.tab.Panel',
xtype: 'tabpanel',
items: [{
title: 'Employee Directory',
xtype: 'grid',
iconCls: 'x-fa fa-users',
listeners: {
itemtap: function(view, index, item, record) { //record is coming from here
Ext.create('QuickApp.view.main.Formdialog'); //I want to create the dialog here WITH the record
}
},
store: Ext.create('QuickApp.store.Employee'),
columns: [{
text: 'First Name',
dataIndex: 'firstName',
flex: 1
}, {
text: 'Last Name',
dataIndex: 'lastName',
flex: 1
}, {
text: 'Phone Number',
dataIndex: 'phoneNumber',
flex: 1
}],
},{
title: 'About Sencha',
iconCls: 'x-fa fa-info-circle'
}]
});
在我的FormDialog.js中,我想收到并使用该记录:
Ext.define('QuickApp.view.main.Formdialog', {
extend: 'Ext.form.Panel',
renderTo: Ext.getBody(),
xtype: 'formpanel',
title: 'Update Record',
floating: true,
centered: true,
width:300,
modal: true,
draggable: true,
record: record, //At least here I need the record from before
viewModel : {
data: {
employee: record
}
},
items: [{
xtype: 'textfield',
name: 'firstname',
label: 'First Name'
}, {
xtype: 'toolbar',
docked: 'bottom',
items: ['->', {
xtype: 'button',
text: 'Submit',
iconCls: 'x-fa fa-check',
handler: function() {
this.up('formpanel').destroy();
}
}, {
xtype: 'button',
text: 'Cancel',
iconCls: 'x-fa fa-close',
handler: function() {
this.up('formpanel').destroy();
}
}]
}]
});
谢谢!
当您像这样创建viewmodel
时,您可以直接在Formdialog
中传递记录
Ext.create({
xtype: 'formdialog',
viewModel: {
data: {
employee: record
}
}
})
或者您也可以使用ViewModel.set()
方法在viewmodel中设置您的记录
form.getViewModel().set('employee', record);
你可以在这里查看工作fiddle。
代码链
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.define('QuickApp.view.main.Formdialog', {
extend: 'Ext.form.Panel',
xtype: 'formdialog',
bodyPadding: 10,
title: 'Update Record',
floating: true,
centered: true,
width: 300,
modal: true,
draggable: true,
items: [{
xtype: 'textfield',
name: 'firstname',
label: 'First Name',
bind: '{employee.firstName}'
}, {
xtype: 'toolbar',
docked: 'bottom',
items: ['->', {
xtype: 'button',
text: 'Submit',
iconCls: 'x-fa fa-check',
handler: function() {
this.up('formpanel').destroy();
}
}, {
xtype: 'button',
text: 'Cancel',
iconCls: 'x-fa fa-close',
handler: function() {
this.up('formpanel').destroy();
}
}]
}]
});
Ext.define('QuickApp.view.main.Main', {
extend: 'Ext.tab.Panel',
xtype: 'maintabpanel',
items: [{
title: 'Employee Directory',
xtype: 'grid',
iconCls: 'x-fa fa-users',
listeners: {
itemtap: function(view, index, item, record) {
Ext.create({
xtype: 'formdialog',
viewModel: {
data: {
employee: record
}
}
}).showBy(item.el);
}
},
store: {
type: 'employee'
},
columns: [{
text: 'First Name',
dataIndex: 'firstName',
flex: 1
}, {
text: 'Last Name',
dataIndex: 'lastName',
flex: 1
}, {
text: 'Phone Number',
dataIndex: 'phoneNumber',
flex: 1
}],
}, {
title: 'About Sencha',
iconCls: 'x-fa fa-info-circle'
}]
});
Ext.create({
xtype: 'maintabpanel',
renderTo: Ext.getBody(),
fullscreen: true
})
}
});