gpt4 book ai didi

javascript - ExtJS:网格和表单之间的两种方式绑定(bind)

转载 作者:行者123 更新时间:2023-11-30 08:32:11 25 4
gpt4 key购买 nike

我正在尝试学习 ExtJS,但有点卡在某个地方。我想创建一个顶部有网格、底部有表格的屏幕。我想将它们彼此绑定(bind),以便当我从网格中选择一行时,表单字段被填充(网格中有相同的记录)并且当我更改网格或表单中的任何内容时,另一侧被更新。

到目前为止,我有一个带有网格和表单的 View 。我有一家为网格提供数据的商店。我被困在这里。如何在表单和网格之间进行双向绑定(bind)。我尝试了谷歌并找到了一些样本 herehere但它们都是单向绑定(bind)的。即如果我在网格上执行以下操作:

           listeners: {

selectionchange: function(model, records) {
var rec = records[0];
var form = Ext.getCmp('chartofaccountsForm');
form.loadRecord(rec);
}
}

它只用当前选定的记录填充表单,但是当我更新表单中的记录时,网格没有更新。

谁能帮我指出正确的方向?任何教程或博客文章都会非常有帮助

最佳答案

试试这个例子:

Ext.widget('container',{
width: 600,
hight: 800,
renderTo: Ext.getBody(),
viewModel: {
formulas: {
selection: {
bind: '{g.selection}',
get: function(selection){
return selection;
}
}
}
},
items: [
{
xtype: 'grid',
title: 'Grid',
reference: 'g',
store: {
type: 'store',
fields: ['id', 'name'],
data: [{id: 1, name: 'foo'}, {id: 2, name: 'bar'}]
},
columns: [
{dataIndex: 'id', header: 'ID'},
{dataIndex: 'name', header: 'Name'}
]
},
{
xtype: 'form',
title: 'Form',
items: [
{
xtype: 'displayfield',
fieldLabel: 'ID',
bind: '{selection.id}'
},
{
xtype: 'textfield',
fieldLabel: 'Name',
bind: '{selection.name}'
}
],
bind: {
hidden: '{!selection}'
}
}
]

});

https://fiddle.sencha.com/#fiddle/179d

关于javascript - ExtJS:网格和表单之间的两种方式绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36039955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com