我正在使用ExtJS 4.2,并且在MySql数据库中有一些记录。我的问题是:如何创建显示数据库中记录的网格?我尝试在servlet中使用ResultSet从数据库中检索记录,但是我不确定如何从那里继续。
如何用数据库中的记录填充网格中的字段?我是ExtJS的新手,我发现很难为此找到解决方案。这与该store
领域有关吗?如果是这样,我该如何达到上述要求?
您需要创建存储,绑定到网格,然后从服务器加载数据。并且确保您需要此ExtJS4的后端,不要提供任何用于处理数据库的工具,例如(取自sencha docs):
Ext.onReady(function(){
Ext.define('Book',{
extend: 'Ext.data.Model',
proxy: {
type: 'ajax',
reader: 'xml'
},
fields: [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
{name: 'Author', mapping: '@author.name'},
'Title', 'Manufacturer', 'ProductGroup'
]
});
// create the Data Store
var store = Ext.create('Ext.data.Store', {
model: 'Book',
autoLoad: true,
proxy: {
// load using HTTP
type: 'ajax',
url: 'sheldon.xml',
// the return will be XML, so lets set up a reader
reader: {
type: 'xml',
// records will have an "Item" tag
record: 'Item',
idProperty: 'ASIN',
totalRecords: '@total'
}
}
});
// create the grid
Ext.create('Ext.grid.Panel', {
store: store,
columns: [
{text: "Author", flex: 1, dataIndex: 'Author'},
{text: "Title", width: 180, dataIndex: 'Title'},
{text: "Manufacturer", width: 115, dataIndex: 'Manufacturer'},
{text: "Product Group", width: 100, dataIndex: 'ProductGroup'}
],
renderTo:'example-grid',
width: 540,
height: 200
});
});
主要思想是-模型用于定义记录的结构和验证(在此处阅读),存储-用于存储和提取(通过解析来自服务器或本地定义数据的响应)与模型结构(基本存储)匹配的记录,最后网格处理一些事件(例如“加载”或“刷新”)并根据网格列定义更新行(docs)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句