猴王牌 2012-04-04 16:02 采纳率: 50%
浏览 461
已采纳

Ext 如何根据对象的属性 给datefield和combobox赋值

我需要根据Session中的用户个人信息 给用户的生日和性别填充值  但是不知道怎么写  这是我的代码

        
    
        //个人信息reader
     var reader=new Ext.data.JsonReader({
            root : 'user'
        }, [{name:'u.id',mapping:'id',type:'integer'}, {
            name : 'u.name',mapping:'name',type:'string'
        }, {
            name : 'u.serialNum',mapping:'serialNum',type:'string'
        }, {
            name : 'u.sex',mapping:'sex',type:'string'
        }, {
            name : 'u.phone',mapping:'phone',type:'string'
        },{
            name:'u.email',mapping:'email',type:'string'
        },{
            name:'u.address',mapping:'address',type:'string'
        },{
            name:'u.idcard',mapping:'idcard',type:'string'
        },{
            name:'u.description',mapping:'description',type:'string'
        },{
            name:'u.takeOfficeDate',mapping:'takeOfficeDate',type:'date'
        },{
            name:'u.telephone',mapping:'telephone',type:'string'
        },{
            name:'u.birthday',mapping:'birthday',type:'date'
        }])
    
    //个人资料Form
        var myInfoForm = new Ext.FormPanel({
                labelAlign : 'right',
                //width:700,
                id:'myInfoFormId',
                fileUpload:true,
                labelWidth : 87,
                reader:reader,
                layout:'column',
                frame : true,
                items : [{
                    columnWidth:.8,
                    items:[{
                    title : "基本信息",
                    xtype : "fieldset",
                    layout : "column",
                    autoHeight : true,
                    autoWidth : true,
                    items : [{
                        layout : "form",
                        columnWidth : .5,
                        items : [{
                                    xtype : "textfield",
                                    fieldLabel : 'id',
                                    hideLabel : true,
                                    hidden : true,
                                    id:'empId',
                                    name : 'u.id'
                                }, {
                                    xtype : "textfield",
                                    fieldLabel : "姓名",
                                    width : 140,
                                    allowBlank : false,
                                    name : "u.name"
                                },{
                                    xtype:"datefield",
                                    fieldLabel:'出生日期',
                                                            id:"takeOfficeDate",
                                    format: 'Y-m-d',
                                    width:140,
                                    name:'u.birthday'
                                }]
                    },{
                        layout:"form",
                        columnWidth:.5,
                        items:[{
                            xtype:"combo",
                            fieldLabel: '性别',
                            width:140,
                            name: 'u.sex',
                            store: new Ext.data.SimpleStore({
                                fields: ['value', 'text'],
                                data: [
                                    ['1', '男'],
                                    ['2', '女']
                                ]
                            }),
                            displayField: 'text',
                            valueField: 'value',
                            mode: 'local',
                            emptyText:'男'
                        }]
                    }]
                }, {
                    title : "用户其他资料",
                    xtype : "fieldset",
                    layout : "column",
                    autoHeight : true,
                    autoWidth : true,
                    items : [{
                                layout : "form",
                                columnWidth : .5,
                                items : [{
                                            xtype : "textfield",
                                            fieldLabel : "手机",
                                            width : 140,
                                            allowBlank : false,
                                            name : "u.phone"
                                        }]
                            }, {
                                layout : "form",
                                columnWidth : .5,
                                items : [{
                                            xtype : "textfield",
                                            fieldLabel : "工作电话",
                                            width : 140,
                                            name : "u.telephone"
                                        }]
                            }, {
                                layout : "form",
                                columnWidth : 1.,
                                items : [{
                                            xtype : "textfield",
                                            fieldLabel : "电子邮箱",
                                            width : 425,
                                            name : "u.email"
                                        }, {
                                            xtype : "textfield",
                                            fieldLabel : "家庭住址",
                                            allowBlank : false,
                                            width : 425,
                                            name : "u.address"
                                        }, {
                                            xtype : "textfield",
                                            fieldLabel : "身份证",
                                            allowBlank : false,
                                            width : 425,
                                            name : "u.idcard"
                                        }]
                            }]
                }]
                },{
                    layout:'column',
                    columnWidth:.2,
                    items:[{
                        layout : "form",
                        columnWidth : 1.,
                        items:[{
                               xtype:'panel',
                               border:false,
                               xtype : 'box',
                               id : 'browseImage',   
                               bodyStyle:'padding:10px 10px 10px 10px;',
                               autoEl : {   
                                   width : 120,   
                                   height : 150,
                                   style:'margin : 16 0 0 10',
                                   tag : 'img' 
                                   //src : avatarurl
                               }  
                        },{
                             xtype : 'button',
                             fieldLabel:'',
                             style:'margin : 20 0 0 40',
                             text:'上传头像',
                             handler: function(){
                                    //方法二,直接调用
                                    var dialog = new Ext.ux.UploadDialog.Dialog({
                                        width: 450,
                                        height: 300,
                                        title: '上传头像',
                                        url:'',
                                        base_params:'',
                                        reset_on_hide: false,
                                        allow_close_on_upload: true
                                    });
                                    
                                    dialog.show();
//                                 var file_path = Ext.getCmp('upload').getValue();
//                                 var str = file_path.substr(file_path.lastIndexOf('.')+1,file_path.length);
//                                 if(str!='JPG'&&str!='jpg'){
//                                 Ext.Msg.alert('错误', "上传的图像只能是jpg格式!"); 
//                                 return false;
//                             }
                               }
                        }]
                    }]
                }]
            });
        
    
            
            
            
            
    //修改个人信息窗口
        var updataInfoWin=new Ext.Window({
                title : '修改我的资料',
                id : 'updataInfoWin',
                constrain : true,// 整个窗口不允许超出浏览器
                modal : true,// 模拟页面失效
                resizable : false,
                width : 770,
                autoHeight : true,
                items : myInfoForm,
                buttons : [{
                    text : '保存',
                    handler : function() {
                        if (!myInfoForm.form.isValid()) {
                            return;
                        }
                        myInfoForm.form.submit({
                            url : 'employee/employee!updateUser.action',
                            method : 'post',
                            waitTitle : "请稍候",
                            waitMsg : '正在更新数据...',
                            success : function(form, action) {
                                if (action.result.success) {
                                    Ext.ensible.sample.msg('操作提示', '员工信息更新成功');
                                }
                            },
                            failure : function(form, action) {
                                Ext.Msg.alert('操作提示', '保存失败,原因可能是:\n'+action.result);
                            }
                        });
                    }
                },{
                    text : '取消',
                    handler : function() {
                        updataInfoWin.hide();
                        //alert(Ext.getCmp('functionPanelID'));
                        //Ext.getCmp('functionPanelID').getActiveTab().hide();
                    }
                }]
        });

    
            
    //最父级容器Panel
    var myInformationPanel=new Ext.Panel({
        title : node.text,
        id : node.text,
        closable : true,
        border:false,
        listeners:{
            'activate':function(){
                updataInfoWin.show();
                myInfoForm.form.load({
                    url:'employee/employee!loadMyInfo.action'
                });
            }
        }
    });
    

 性别写上后 可以正确显示 但是再点下拉 就只剩填充上的性别了   比如 用户是女的  cobbobox显示是女  但是点下拉  发现里面只有女的选项了

  • 写回答

1条回答 默认 最新

  • yxc_gdut 2012-04-10 16:52
    关注

    combobox中加入属性 triggerAction: 'all',

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题