如何从控制器获取值到表单
How to get a value from controller to form
我在 ExtJS4 中构建了一个 master/detail 表单作为学习 ExtJS 的练习。
我想在创建新文章时将 id
从 master table 传递给 detail
表单。
当在 detailGrid
中按下 create
按钮时,id
被传递到 controller
。在 controller
中,我可以通过 console.log
看到 id
的输出,所以我知道它存在于 controller
中。
我怎样才能将它传递给表单?
控制器:
{
var detailgrid = button.up('userdetail');
var parentId = detailgrid.getParentId();
console.log(parentId);
var view = Ext.widget('detailadd');
},
我需要从 controller
中获取 parentId
的表格
Ext.define('calsberg.view.user.DetailsAdd', {
extend: 'Ext.window.Window',
alias: 'widget.detailadd',
title: 'Add Artikli',
config:
{
parentId: parentId
},
layout: 'fit',
autoShow: true,
initComponent: function () {
this.items = [
{
xtype: 'form',
bodyStyle: {
background: 'none',
padding: '10px',
border: '0'
},
items: [
{
xtype: 'textfield',
name: 'parentId',
value: this.getParentId()
},
{
xtype: 'textfield',
name: 'sifra',
allowBlank: false,
fieldLabel: 'Šifra'
},
{
xtype: 'textfield',
name: 'naziv',
allowBlank: false,
vtype: 'naziv',
fieldLabel: 'Naziv'
},
您可以将变量放在全局命名空间中,以便您可以在应用程序的任何地方引用它,例如
// MyApp would already be initialised in app.js
MyApp.parentId = detailgrid.getParentId();
// then you could reference it anywhere else thereafter
Ext.define('calsberg.view.user.DetailsAdd', {
extend: 'Ext.window.Window',
alias: 'widget.detailadd',
title: 'Add Artikli',
config:
{
parentId: MyApp.parentId
}
.....
或者您可以在创建像这样的小部件时传入配置对象
var detailgrid = button.up('userdetail');
var parentId = detailgrid.getParentId();
console.log(parentId);
var view = Ext.widget('detailadd', {config:{parentId:parentId}});
我在 ExtJS4 中构建了一个 master/detail 表单作为学习 ExtJS 的练习。
我想在创建新文章时将 id
从 master table 传递给 detail
表单。
当在 detailGrid
中按下 create
按钮时,id
被传递到 controller
。在 controller
中,我可以通过 console.log
看到 id
的输出,所以我知道它存在于 controller
中。
我怎样才能将它传递给表单?
控制器:
{
var detailgrid = button.up('userdetail');
var parentId = detailgrid.getParentId();
console.log(parentId);
var view = Ext.widget('detailadd');
},
我需要从 controller
parentId
的表格
Ext.define('calsberg.view.user.DetailsAdd', {
extend: 'Ext.window.Window',
alias: 'widget.detailadd',
title: 'Add Artikli',
config:
{
parentId: parentId
},
layout: 'fit',
autoShow: true,
initComponent: function () {
this.items = [
{
xtype: 'form',
bodyStyle: {
background: 'none',
padding: '10px',
border: '0'
},
items: [
{
xtype: 'textfield',
name: 'parentId',
value: this.getParentId()
},
{
xtype: 'textfield',
name: 'sifra',
allowBlank: false,
fieldLabel: 'Šifra'
},
{
xtype: 'textfield',
name: 'naziv',
allowBlank: false,
vtype: 'naziv',
fieldLabel: 'Naziv'
},
您可以将变量放在全局命名空间中,以便您可以在应用程序的任何地方引用它,例如
// MyApp would already be initialised in app.js
MyApp.parentId = detailgrid.getParentId();
// then you could reference it anywhere else thereafter
Ext.define('calsberg.view.user.DetailsAdd', {
extend: 'Ext.window.Window',
alias: 'widget.detailadd',
title: 'Add Artikli',
config:
{
parentId: MyApp.parentId
}
.....
或者您可以在创建像这样的小部件时传入配置对象
var detailgrid = button.up('userdetail');
var parentId = detailgrid.getParentId();
console.log(parentId);
var view = Ext.widget('detailadd', {config:{parentId:parentId}});