Nis*_*ish 4 data-binding grid extjs mvvm viewmodel
我有一个带有一个文本字段和一个网格的表单面板。现在,我想userinput通过 ViewModel 获取并获取值json以将其发送到服务器。
这里的问题是,我能够绑定文本字段,因此我将文本字段值作为视图模型中的一个参数,但是如何将选定的网格行数据作为viewMolde.getData().
例如:
模型:
Ext.define('UserModel', {
extend: 'Ext.data.Model',
fields: [{
name: "name",
type: "string"
}, {
name: "gridRecord",
type: "auto"
}]
});
Run Code Online (Sandbox Code Playgroud)
查看型号:
Ext.define('QAVM', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.QAVM',
model: 'UserModel'
});
Run Code Online (Sandbox Code Playgroud)
看法 :
Ext.define('View', {
extend: 'Ext.form.Panel',
xtype: 'app-test',
viewModel: 'QAVM',
items: [{
xtype: 'textfield',
fieldLabel: 'TestInt',
bind: '{name}' /**ABLE TO BIND and GETTING VALUE In viewModel.getData()*/
}, {
xtype: 'grid',
title: 'Simpsons',
formBind: true,
store: 'storeName',
bind: {
selection: 'gridSelectedRecord'
}, //HOW TO BIND GRID SELECTED RECORD TO MODEL'S SECOND FIELD "gridRecord"
columns: [{
text: 'Address-1',
dataIndex: 'addr'
}, {
text: 'Pincode',
dataIndex: 'pincode',
flex: 1
}]
}]
});
Run Code Online (Sandbox Code Playgroud)
首先我想说imo你的方法是错误的。您不想通过从viewmodel. 您想通过或proxy上的将您的记录发送到服务器。您的数据应该仅用于绑定到您的. 在和您的服务器的数据。但是 a可以通过 a 绑定(和过滤)到您的.modelstoreviewmodelviewstoremodelsstoreviewmodelview
Model-View-ViewModel是一种模式,其中modelis 用于您的数据(并通过 迁移proxy),view表示您的数据并将viewmodel您model和您的数据粘合view在一起。
现在我的答案。
你可以formulas在你的viewmodel. 然后,您可以将网格的当前选择深度绑定到您的表单。
视图模型:
Ext.define('MyApp.view.group.GroupsModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.group-groups',
stores: {
allgroups: {
source: 'Groups',
sorters: {
property: 'name',
direction: 'ASC'
}
}
},
data: {
title: 'Groups'
},
formulas: {
currentRecord: {
// We need to bind deep to be notified on each model change
bind: {
bindTo: '{groupGrid.selection}', //--> reference configurated on the grid view (reference: groupGrid)
deep: true
},
get: function(record) {
return record;
},
set: function(record) {
if (!record.isModel) {
record = this.get('records').getById(record);
}
this.set('currentRecord', record);
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
看法:
Ext.define('MyApp.view.group.Groups', {
extend: 'Ext.container.Container',
xtype: 'groups',
requires: [
'MyApp.view.group.GroupsController',
'MyApp.view.group.GroupsModel',
'Ext.grid.column.Boolean',
'Ext.form.field.Checkbox',
'Ext.form.field.TextArea',
'Ext.form.field.Text'
],
controller: "group-groups",
viewModel: {
type: "group-groups"
},
layout: {
type: 'hbox',
pack: 'start',
align: 'stretch'
},
style: {
backgroundColor: '#f5f5f5'
},
items: [{
xtype: 'grid',
reference: 'groupGrid', //--> used in the viewmodel
flex: 1,
bind: {
title: '{title}',
store: '{allgroups}'
},
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Description',
dataIndex: 'description',
flex: 1
}, {
xtype: 'booleancolumn',
text: 'Active',
trueText: 'Yes',
falseText: 'No',
dataIndex: 'isActive'
}]
}, {
xtype: 'form',
title: 'Details',
bodyPadding: 15,
minWidth: 300,
split: true,
defaults: {
xtype: 'textfield',
anchor: '100%',
allowBlank: false,
enforceMaxLength: true
},
items: [{
fieldLabel: 'Name',
bind: '{currentRecord.name}' //--> get current selected record from viewmodel
}, {
xtype: 'textarea',
fieldLabel: 'Description',
bind: '{currentRecord.description}',
height: 120
}, {
xtype: 'checkboxfield',
fieldLabel: 'Active',
bind: '{currentRecord.isActive}'
}]
}]
});
Run Code Online (Sandbox Code Playgroud)
在编辑model或添加模型到您的store保存/同步您store或保存您的model.
| 归档时间: |
|
| 查看次数: |
14650 次 |
| 最近记录: |