Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从控制器设置窗口字段值_Javascript_Ajax_Extjs_Extjs Mvc - Fatal编程技术网

Javascript 从控制器设置窗口字段值

Javascript 从控制器设置窗口字段值,javascript,ajax,extjs,extjs-mvc,Javascript,Ajax,Extjs,Extjs Mvc,我有一个窗口,当单击某个单元格时,在弹出窗口中显示有关用户的值。。在我的UserController中,我根据id加载用户的json,是否有任何方法将此json的特定值传递到我的窗口中?我知道如果是表单,我可以使用.getForm().setValues()。我能在我的窗户里嵌套一张表格吗 控制器代码段: loadUserDetails: function(userId) { var view = Ext.widget('userdetails').show();

我有一个窗口,当单击某个单元格时,在弹出窗口中显示有关用户的值。。在我的UserController中,我根据id加载用户的json,是否有任何方法将此json的特定值传递到我的窗口中?我知道如果是表单,我可以使用.getForm().setValues()。我能在我的窗户里嵌套一张表格吗

控制器代码段:

loadUserDetails: function(userId) {
        var view = Ext.widget('userdetails').show();
        Ext.Ajax.request({
            url:  /user/get.htm?alt=json',
                params: { id: userId },
            success: function(response) {
                var json = Ext.JSON.decode(response.responseText);
            }
        });
    }
查看代码段(窗口):

鉴于这一类别:

Ext.define('App.view.user.UserDetails', {
    extend: 'Ext.window.Window'
    ,alias: 'widget.userdetails'
    ,id: 'userdetails'
    ,title: 'User Details'
    ,height: 300
    ,width: 380
    ,items: [{
        xtype: 'fieldset',
        title: 'Information',
        margin: '5',
        width: 350,
        height: 250,
        defaults: {xtype: 'displayfield', margin: '3', labelWidth: 100, width: 300},
        items: [{
            // you should avoid using fixed id that will prevent using the component
            // multiple times
            // id: 'id',
            width: 150,
            fieldLabel: 'User Id'

            ,itemId: 'userId' // <= add item id for easy retrieval
        },{
            // id: 'email',
            width: 250,
            fieldLabel: 'User Email'

            ,name: 'userEmail' // <= or a name, as is logical for a field
        }]
    }]
});
或者,您可以在窗口中嵌套一个表单,以便使用
设置值
(和其他表单功能):

Ext.define('App.view.user.UserDetails', {
    extend: 'Ext.window.Window'
    ,alias: 'widget.userdetails'
    ,id: 'userdetails'
    ,title: 'User Details'
    ,height: 300
    ,width: 380
    ,items: [{
        xtype: 'fieldset',
        title: 'Information',
        margin: '5',
        width: 350,
        height: 250,
        defaults: {xtype: 'displayfield', margin: '3', labelWidth: 100, width: 300},
        items: [{
            // you should avoid using fixed id that will prevent using the component
            // multiple times
            // id: 'id',
            width: 150,
            fieldLabel: 'User Id'

            ,itemId: 'userId' // <= add item id for easy retrieval
        },{
            // id: 'email',
            width: 250,
            fieldLabel: 'User Email'

            ,name: 'userEmail' // <= or a name, as is logical for a field
        }]
    }]
});
var win = Ext.create('App.view.user.UserDetails', {
    autoShow: true
});

// query by itemId
win.down('#userId').setValue(123);

// or by name
win.down('field[name=userEmail]').setValue('user@example.com');
Ext.define('App.view.user.UserDetails', {
    extend: 'Ext.window.Window'
    ,alias: 'widget.userdetails'
    ,id: 'userdetails'
    ,title: 'User Details'
    ,height: 300
    ,width: 380
    ,layout: 'fit'
    ,items: [{
        xtype: 'form'
        ,items: [{
            xtype: 'fieldset',
            title: 'Information',
            margin: '5',
            width: 350,
            height: 250,
            defaults: {xtype: 'displayfield', margin: '3', labelWidth: 100, width: 300},
            items: [{
                width: 150,
                fieldLabel: 'User Id'
                // name is required for setValues to work
                ,name: 'userId'
            },{
                // id: 'email',
                width: 250,
                fieldLabel: 'User Email'
                ,name: 'userEmail'
            }]
        }]
    }]
});

var win = Ext.create('App.view.user.UserDetails', {
    autoShow: true
});

win.down('form').setValues({
    ...
});