组合失去了选定的价值

时间:2015-01-10 01:34:20

标签: java spring extjs model-view-controller

我有一个名为Customer的表,另一个名为Country。客户有一个国家,我在我的客户模型中使用了属于关联。 。在数据库中插入从组合中选择的国家/地区时出现问题。我在网格中加载值没有任何问题。我不知道为什么会这样!

代码下方:

国家/地区型号:

Ext.define('app.model.Country', {
extend: 'Ext.data.Model',
fields: [{name:'name', type:'string'}, 'isActive']
});

客户模式:

Ext.define('app.model.Customer', {
extend : 'Ext.data.Model',
fields : [ {
    name : 'name',
    type : 'string'
}, {
    name : 'isActive',
    type : 'string'
}],
belongsTo: [
            {
                name: 'country',
                instanceName: 'country',
                model: 'app.model.Country',
                getterName: 'getCountry',
                setterName: 'setCountry',
                associationKey: 'country'
            }
        ]
 });

国家商店:

 Ext.define('app.store.Countries', {
extend : 'Ext.data.Store',
model : 'app.model.Country',
autoLoad: true,
pageSize: 35,
autoLoad: {start: 0, limit: 35},

    proxy: {
        type: 'ajax',
        api: {
            read : 'country/view.action',
            create : 'country/create.action',
            update: 'country/update.action',
            destroy: 'country/delete.action'
        },
        reader: {
            type: 'json',
            root: 'data',
            successProperty: 'success'
        },
        writer: {
            type: 'json',
            writeAllFields: true,
            encode: true,
            root: 'data'
        },
        listeners: {
            exception: function(proxy, response, operation){
                Ext.MessageBox.show({
                    title: 'REMOTE EXCEPTION',
                    msg: operation.getError(),
                    icon: Ext.MessageBox.ERROR,
                    buttons: Ext.Msg.OK
                });
            }
        }
    }
});

客户商店:

 Ext.define('app.store.Customers', {
extend : 'Ext.data.Store',
model : 'app.model.Customer',
autoLoad: true,
pageSize: 35,
autoLoad: {start: 0, limit: 35},

    proxy: {
        type: 'ajax',
        api: {
            read : 'customer/view.action',
            create : 'customer/create.action',
            update: 'customer/update.action'
        },
        reader: {
            type: 'json',
            root: 'data',
            successProperty: 'success'
        },
        writer: {
            type: 'json',
            writeAllFields: true,
            encode: true,
            root: 'data'
        },
        listeners: {
            exception: function(proxy, response, operation){
                Ext.MessageBox.show({
                    title: 'REMOTE EXCEPTION',
                    msg: operation.getError(),
                    icon: Ext.MessageBox.ERROR,
                    buttons: Ext.Msg.OK
                });
            }
        }
    }
 });

国家/地区控制器

Ext.define('app.controller.Countries', {
extend : 'Ext.app.Controller',

views : [ 'country.List', 'country.Edit' ],
stores : [ 'Countries' ],
models : [ 'Country' ],

init : function() {
    this.control({
        'window > countrylist': {
            itemdblclick: this.editCountry
        },
        'countryedit [action=save]' : {
            click : this.save
        },
        'countrylist [action=editcountry]' : {
            click : this.edit
        },
    });
},
editCountry : function(grid,record) {
    var view = Ext.widget('countryedit');
    view.down('form').loadRecord(record);
}
    ,
edit : function(button) {
    var view = Ext.widget('countryedit');
},

save : function(button) {
    var win = button.up('window'), form = win.down('form'), record = form
            .getRecord(), values = form.getValues();// var store =
    var isNew = (record == null)                                        //        
    Ext.getStore('Users');
    if (isNew) {            
        record = Ext.create('app.model.Country');
           record.set(values);
            this.getCountriesStore().add(record);
           this.getCountriesStore().sync();
       } else {
            record.set(values);
            this.getCountriesStore().sync();
       }
       win.close();
   },
 });

客户控制器

Ext.define('app.controller.Customers', {
extend : 'Ext.app.Controller',
views : [ 'customer.List', 'customer.Edit' ],
stores : [ 'Customers', 'Countries' ],
models : [ 'Customer' ],

init : function() {
    this.control({
        'window > customerlist' : {
            itemdblclick : this.editCustomer
        },
        'customeredit [action=save]' : {
            click : this.save
        },
        'customerlist [action=editcustomer]' : {
            click : this.edit
        },
    });
},
editCustomer : function(grid, record) {
    var view = Ext.widget('customeredit');
    view.down('form').loadRecord(record);
},
edit : function(button) {
    var view = Ext.widget('customeredit');
},

save : function(button) {
    var win = button.up('window'), form = win.down('form'), record = form
            .getRecord(), values = form.getValues();// var store =
    var isNew = (record == null) // Ext.getStore('Users');
    if (isNew) {
        record = Ext.create('app.model.Customer');
        record.set(values);
        this.getCustomersStore().add(record);
        this.getCustomersStore().sync();
    } else {
        record.set(values);
        this.getCustomersStore().sync();
    }
    win.close();
 },
});

接下来,我的意见......

国家/地区列表

Ext.define('app.view.country.List' ,{
extend: 'Ext.grid.Panel',
alias: 'widget.countrylist',
store: 'Countries',
columns: [
    {header: "NAME",
     width: 170,
     sortable: true,
     dataIndex: 'name'
    },
    {header: "ISACTIVE",
     width: 160,
     sortable: true,
     dataIndex: 'isActive'
    }
],
viewConfig:{forcefit:true},
title: 'My Countries',
height: 500,
width:535,
frame:true,
tbar: [{
    iconCls: 'icon-user-add',
    text: 'Add Country',
    action: 'editcountry'
}]
});

国家/地区编辑:这是表格!

Ext.define('app.view.country.Edit', {
extend : 'Ext.window.Window',
alias : 'widget.countryedit',

title : 'Add Country',
layout : 'fit',
autoShow : true,
modal:true,

initComponent : function() {
    this.items = [ {
        xtype : 'form',
        items : [ {
            xtype : 'textfield',
            name : 'name',
            fieldLabel : 'Name'
        }, {
            xtype : 'checkbox',
            name : 'isActive',
            fieldLabel : 'IsActive',
            checked : true,
            inputValue : 'Y',
            uncheckedValue : 'N'
        } ]
    } ];

    this.buttons = [ {
        text : 'Save',
        action : 'save'
    }, {
        text : 'Cancel',
        scope : this,
        handler : this.close
    } ];

    this.callParent(arguments);
}
});

客户列表

Ext.define('app.view.customer.List', {
extend : 'Ext.grid.Panel',
alias : 'widget.customerlist',
store : 'Customers',
columns : [ {
    header : "NAME",
    width : 170,
    sortable : true,
    dataIndex : 'name'
}, {
    header : "ISACTIVE",
    width : 160,
    sortable : true,
    dataIndex : 'isActive'
}, {
    header : 'COUNTRY',
    xtype : 'templatecolumn',
    tpl : '{country.name}'
},

],
viewConfig : {
    forcefit : true
},
title : 'My Customers',
height : 500,
width : 535,
frame : true,
tbar : [ {
    iconCls : 'icon-user-add',
    text : 'Add Customer',
    action : 'editcustomer'
} ]
});

客户编辑

Ext.define('app.view.customer.Edit', {
extend : 'Ext.window.Window',
alias : 'widget.customeredit',
title : 'Edit Customer',
layout : 'fit',
autoShow : true,
modal : true,

initComponent : function() {
    this.items = [ {
        xtype : 'form',
        items : [ {
            xtype : 'textfield',
            name : 'name',
            fieldLabel : 'Name'
        }, {
            xtype : 'checkbox',
            name : 'isActive',
            fieldLabel : 'IsActive',
            checked : true,
            inputValue : 'Y',
            uncheckedValue : 'N'
        }, {
            xtype : 'combo',
            name : 'country_id',
            displayField : 'name',
            fieldLabel : 'Country',
            store : 'Countries',
            valueField : 'id',
            queryMode : 'remote'

        } ]
    } ];

    this.buttons = [ {
        text : 'Save',
        action : 'save'
    }, {
        text : 'Cancel',
        scope : this,
        handler : this.close
    } ];

    this.callParent(arguments);

}
});

0 个答案:

没有答案