EXT-js PropertyGrid 实现更新的最佳实践?
我在一个项目中使用 EXT-js,通常 使用 EXT-js 一切都非常简单,但是对于 propertyGrid,我不确定。 我想要一些关于这段代码的建议。
首先是商店填充属性网格, 在加载事件上:
var configStore = new Ext.data.JsonStore({
// store config
autoLoad:true,
url: url.remote,
baseParams : {xaction : 'read'},
storeId: 'configStore',
// reader config
idProperty: 'id_config',
root: 'config',
totalProperty: 'totalcount',
fields: [{
name: 'id_config'
}, {
name: 'email_admin'
}
, {
name: 'default_from_addr'
}
, {
name: 'default_from_name'
}
, {
name: 'default_smtp'
}
],listeners: {
load: {
fn: function(store, records, options){
// get the property grid component
var propGrid = Ext.getCmp('propGrid');
// make sure the property grid exists
if (propGrid) {
// populate the property grid with store data
propGrid.setSource(store.getAt(0).data);
}
}
}
}
});
这是 propertyGrid:
var propsGrid = new Ext.grid.PropertyGrid({
renderTo: 'prop-grid',
id: 'propGrid',
width: 462,
autoHeight: true,
propertyNames: {
tested: 'QA',
borderWidth: 'Border Width'
},
viewConfig : {
forceFit: true,
scrollOffset: 2 // the grid will never have scrollbars
}
});
到目前为止一切顺利,但是使用下一个按钮,我将触发旧式更新, 我的问题是:
这是更新此组件的正确方法吗? 或者使用编辑器更好? 或其他东西...
对于常规网格,我使用存储方法来执行更新、删除等...
这个示例确实很少! 即使在有关 ext-js 的书籍中也是如此!
new Ext.Button({
renderTo: 'button-container',
text: 'Update',
handler: function(){
var grid = Ext.getCmp("propGrid");
var source = grid.getSource();
var jsonDataStr = null;
jsonDataStr = Ext.encode(source);
var requestCg = {
url : url.update,
method : 'post',
params : {
config : jsonDataStr , xaction : 'update'
},
timeout : 120000,
callback : function(options, success, response) {
alert(success + "\t" + response);
}
};
Ext.Ajax.request(requestCg);
}
});
感谢您的阅读。
I am using EXT-js for a project, usually everything is pretty straight forward with EXT-js, but with the propertyGrid, I am not sure.
I'd like some advice about this piece of code.
First the store to populate the property grid,
on the load event:
var configStore = new Ext.data.JsonStore({
// store config
autoLoad:true,
url: url.remote,
baseParams : {xaction : 'read'},
storeId: 'configStore',
// reader config
idProperty: 'id_config',
root: 'config',
totalProperty: 'totalcount',
fields: [{
name: 'id_config'
}, {
name: 'email_admin'
}
, {
name: 'default_from_addr'
}
, {
name: 'default_from_name'
}
, {
name: 'default_smtp'
}
],listeners: {
load: {
fn: function(store, records, options){
// get the property grid component
var propGrid = Ext.getCmp('propGrid');
// make sure the property grid exists
if (propGrid) {
// populate the property grid with store data
propGrid.setSource(store.getAt(0).data);
}
}
}
}
});
here is the propertyGrid:
var propsGrid = new Ext.grid.PropertyGrid({
renderTo: 'prop-grid',
id: 'propGrid',
width: 462,
autoHeight: true,
propertyNames: {
tested: 'QA',
borderWidth: 'Border Width'
},
viewConfig : {
forceFit: true,
scrollOffset: 2 // the grid will never have scrollbars
}
});
So far so good, but with the next button, I'll trigger an old school update,
and my question :
Is that the proper way to update this component ?
Or is it better to user an editor ?
or something else...
for regular grid I use the store methods to do the update, delete,etc...
The examples are really scarce on this one!
Even in books about ext-js!
new Ext.Button({
renderTo: 'button-container',
text: 'Update',
handler: function(){
var grid = Ext.getCmp("propGrid");
var source = grid.getSource();
var jsonDataStr = null;
jsonDataStr = Ext.encode(source);
var requestCg = {
url : url.update,
method : 'post',
params : {
config : jsonDataStr , xaction : 'update'
},
timeout : 120000,
callback : function(options, success, response) {
alert(success + "\t" + response);
}
};
Ext.Ajax.request(requestCg);
}
});
and thanks for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那应该没问题。 PropertyGrid 和支持类很早就包含在 Ext 中,甚至早于当前 Ext.data.* 命名空间中的许多类。它从未真正得到完全更新以匹配其他标准数据类上可用的 API。 PropertyGrid 实际上确实在底层使用了一个普通的 Ext.data.Store 来存储其数据,但典型的存储方法和事件并未公开。因此,您要么必须使用
getSource()
,要么开始进行一些主要的覆盖。That should be fine. The PropertyGrid and supporting classes were included early on in Ext, even before a lot of the classes in the current Ext.data.* namespace. It never really got fully updated to match the APIs available on the other standard data classes. The PropertyGrid actually does use a plain Ext.data.Store under the hood to store its data, but the typical store methods and events are not exposed. As such, you'll either have to make do with
getSource()
or else start doing some major overriding.