如何将存储值分配给隐藏字段 [英] How to assign Store value to hidden field
问题描述
我有一个模型和一个商店,我需要为商店的隐藏字段分配一个值.
I have a model and store and I need to assign a value to the hidden field from the store.
Ext.define('loginUser', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', mapping: 'Provider.id' },
{ name: 'name', mapping: 'Provider.name' }
]
});
loggedUser = Ext.create('Ext.data.Store', {
model: 'loginUser',
autoLoad: true,
proxy: {
type: 'ajax',
url : url+'/lochweb/loch/users/getLoggedUser',
reader: {
type: 'json',
root: 'Users'
}
}
});
我需要按如下所示将商店值分配给隐藏字段
I need to assign the store value to hidden field as follows,
CProvider = new Ext.create('Ext.ux.form', {
items: [{
xtype:'hidden',
name:'clearingHouseID',
store:loggedUser
value:id
}]
});
,但未将值分配给隐藏值.有什么办法将其存储值分配给隐藏字段?
but the value is not assigned to hidden value. Is there any way assign it store value to hidden field?
谢谢
推荐答案
您可以使用表单的loadRecord函数将记录绑定到表单.遵循以下原则:
You can bind a record to a form by using the form's loadRecord function. Something along these lines:
loggedUser.on('load', function (store, records, success) {
if (success && records.length === 1) {
CProvider.loadRecord(records[0]);
}
});
然后将表单字段更改为要在模型中存储在隐藏字段中的字段名称.
Then change the form field to have a name of the field in the model you want to be stored in the hidden field.
CProvider = new Ext.create('Ext.ux.form', {
items: [{
xtype:'hidden',
name:'name',
store:loggedUser
value:id
}]
});
隐藏字段只能存储要加载到表单中的模型的一个字段的值.
The hidden field can only store one field's value of the model you are loading into the form.
这篇关于如何将存储值分配给隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!