Ext.define('MyApp.view.homepage.ConsoleFirstLevelAdvert' ,{
extend: 'Ext.grid.Panel',
alias: 'widget.consolefirstleveladvert',
requires:['Ext.toolbar.Paging','Ext.data.*','Ext.util.*','Ext.grid.*','Ext.state.*'],
id:'homepageconsolefirstleveladvert',
closable:true,
initComponent: function() {
var rowEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToMoveEditor: 1,
autoCancel: false
});
var store = new Ext.data.JsonStore({
storeId: 'listconsolefirstleveladvert',
pageSize:2,
proxy: {
type: 'ajax',
api: {
read: 'listconsolefirstleveladvert.do',
update: 'update_consolefirstleveladvert.do',
},
reader: {
type: 'json',
root: 'root',
totalProperty :'totalProperty'
},
writer: {
type: 'json',
allowSingle: false,
writeAllFields: true,
root: 'data'
}
},
autoSync: true,
autoLoad: {start: 0, limit: 2},
fields: ['productId', 'productTitle', 'productName','productPrice','pictureUrl', 'productDeposit', 'categoryId','url']
});
this.plugins=[rowEditing];
this.store =store;
this.columns = [
{header: '编号', dataIndex: 'productId', hidden:true, flex: 1},
{header: '产品标题', dataIndex: 'productTitle',editor:'textfield', flex: 1},
{header: '产品名称', dataIndex: 'productName', editor: 'textfield',flex: 1},
{header: '产品价格', dataIndex: 'productPrice', editor: 'numberfield',flex: 1},
{header: '图片地址', dataIndex: 'pictureUrl',editor: 'textfield', flex: 1},
{header: '商品库存', dataIndex: 'productDeposit', flex: 1},
{header: '类目ID', dataIndex: 'categoryId', flex: 1},
{header: '详细页面', dataIndex: 'url', editor: 'textfield',flex: 1}
];
this.dockedItems = [{
xtype: 'pagingtoolbar',
store: store, // same store GridPanel is using
dock: 'bottom',
displayInfo: true,
displayMsg: '显示 {0} - {1} 条,共计 {2} 条',
emptyMsg: "没有数据"
},{
xtype: 'toolbar',
dock: 'top',
items: [
{
xtype: 'button',
text: '增加' ,
handler:function(){
rowEditing.cancelEdit();
// var panelModel = Ext.getCmp('homepageconsolefirstleveladvert').getSelectionModel();
// var panelModel = this.up("panel").getSelectionModel();
var panelModel = this.up("panel").getSelectionModel();
store.insert(0,panelModel);
rowEditing.startEdit(0, 0);
}
},
{ xtype: 'button', text: '删除' },
{ xtype: 'button', text: '修改' ,handler:function(){
store.sync();
store.reload();
}
}]
}];
this.callParent();
},
listeners : {
itemdblclick: function(dv, record, item, index, e) {
}
},
});
代码如上所示,异常情况如下:
点击添加按钮时运行到这行代码: store.insert(0,panelModel);时报错:TypeError: q is undefined ext-all.js(第21行);
var _rs = new Ext.data.Record({productId:'',productTitle:'',productName:'',productPrice:'',pictureUrl:'',productDeposit:'',categoryId:'',url:''});
this.getStore().add(_rs) ;
大哥,你那个定义变量的代码我允许就报错说:TypeError: n.fields is undefined
@xiezhong: 我不是男的。你可以叫姐!我刚才没看到你的这个是4.2的版本,看了楼上的评论才知道的,不好意思哈!这个是在3.0里面是这样写的!
@xiezhong: 我没有玩儿过4.2版本,我在网上搜了一下,看到这个例子是4.0的。里面有两行新增的代码,你试一下看可以吗
http://hi.baidu.com/peter_zk/item/ba2ff0538d4aa1aeacc85781
var newRecord = new this.Model(rowData);//rowData就是初始化的数据
this.Store.add(newRecord);
this 是你的grid
rowData该如何初始化呢?我是新手,第一次接触EXT
@xiezhong: 类似于楼下的:{productId:'',productTitle:'',productName:'',productPrice:'',pictureUrl:'',productDeposit:'',categoryId:'',url:''}
@菜鸟的故事: 楼下的那个定义变量的代码我运行的时候也报错:TypeError: n.fields is undefined
还有我查了EXT4.2的API里面好像没有看见Ext.data.Record这个类!这是怎么回事呀?
@xiezhong: 好像4.0以后就把这个类取消了,改成Model了,相当于表结构