Extjs4 无法从extjs 4中的表布局获取存储数据
我正在尝试从store.com获取数据,我想在extjs面板中的表布局上使用它,但总是得到一个空字符串,尽管数据是在控制台中打印的。任何指点都将不胜感激Extjs4 无法从extjs 4中的表布局获取存储数据,extjs4,Extjs4,我正在尝试从store.com获取数据,我想在extjs面板中的表布局上使用它,但总是得到一个空字符串,尽管数据是在控制台中打印的。任何指点都将不胜感激 <code> Ext.onReady(function(){ Ext.define('Account', { extend: 'Ext.data.Model', fields: [ 'id',
<code>
Ext.onReady(function(){
Ext.define('Account', {
extend: 'Ext.data.Model',
fields: [
'id',
'name',
'nooflicenses'
]
});
var store = Ext.create('Ext.data.Store', {
model: 'Account',
autoSync: true,
proxy: {
type: 'ajax',
api: {
read: "accounts"
},
reader: {
type: 'json',
root: 'Account',
successProperty: 'success',
messageProperty: 'message',
totalProperty: 'results',
idProperty: 'id'
},
listeners: {
exception: function(proxy, type, action, o, result, records) {
if (type = 'remote') {
Ext.Msg.alert("Could not ");
} else if (type = 'response') {
Ext.Msg.alert("Could not " + action, "Server's response could not be decoded");
} else {
Ext.Msg.alert("Store sync failed", "Unknown error");}
}
}//end of listeners
}//end of proxy
});
store.load();
store.on('load', function(store, records) {
for (var i = 0; i < records.length; i++) {
console.log(store.data.items[0].data['name']); //data printed successfully here
console.log(store.getProxy().getReader().rawData);
console.log(store);
};
});
function syncStore(rowEditing, changes, r, rowIndex) {
store.save();
}
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
autoCancel: false,
saveText: 'Save',
listeners: {
afteredit: syncStore
}
});
var grid = Ext.create('Ext.panel.Panel', {
title: 'Table Layout',
width: 500,
height:'30%',
store: store,
layout: {
type: 'table',
// The total column count must be specified here
columns: 2,
tableAttrs: {
style: {
width: '100%',
height:'100%'
}
},
tdAttrs: {
style: {
height:'10%'
}
}
},
defaults: {
// applied to each contained panel
bodyStyle:'border:0px;',
xtype:'displayfield',
labelWidth: 120
},
items: [{
fieldLabel: 'My Field1',
name :'nooflicenses',
value: store //How to get the data here
//bodyStyle:'background-color:red;'
},{
fieldLabel: 'My Field',
name:'name',
value:'name'
}],
renderTo: document.getElementById("grid1")
});
});
</code>
Ext.onReady(函数(){
Ext.define('账户'{
扩展:“Ext.data.Model”,
字段:[
“id”,
“姓名”,
“无飞行许可证”
]
});
var store=Ext.create('Ext.data.store'{
模型:'帐户',
自动同步:对,
代理:{
键入:“ajax”,
api:{
改为:“账户”
},
读者:{
键入:“json”,
root:'帐户',
successProperty:“成功”,
messageProperty:'消息',
totalProperty:'结果',
idProperty:“id”
},
听众:{
异常:函数(代理、类型、操作、o、结果、记录){
如果(类型='remote'){
Ext.Msg.alert(“无法”);
}else if(类型='response'){
Ext.Msg.alert(“无法”+操作,“无法解码服务器的响应”);
}否则{
Ext.Msg.alert(“存储同步失败”,“未知错误”);}
}
}//听众结束
}//代理结束
});
store.load();
store.on('load',函数(存储,记录){
对于(var i=0;i
显示数据的最“本机”方式是使用Ext.grid.Panel
例如:
外部应用程序({
名称:'learnample'
launch: function() {
//Create Store
Ext.create ('Ext.data.Store', {
storeId: 'example1',
fields: ['name','email'],
autoLoad: true,
data: [
{name: 'Ed', email: 'ed@sencha.com'},
{name: 'Tommy', email: 'tommy@sencha.com'}
]
});
Ext.create ('Ext.grid.Panel', {
title: 'example1',
store: Ext.data.StoreManager.lookup('example1'),
columns: [
{header: 'Name', dataIndex: 'name', flex: 1},
{header: 'Email', dataIndex: 'email', flex: 1}
],
renderTo: Ext.getBody()
});
}
}))
网格可以按照用户需求定制的方式进行配置
如果您有使用Ext.panel.panel和表布局的特定原因,可以使用XTemplate,但绑定数据会更复杂 显示数据的最“本机”方式是使用Ext.grid.Panel
例如:
外部应用程序({
名称:'learnample'
launch: function() {
//Create Store
Ext.create ('Ext.data.Store', {
storeId: 'example1',
fields: ['name','email'],
autoLoad: true,
data: [
{name: 'Ed', email: 'ed@sencha.com'},
{name: 'Tommy', email: 'tommy@sencha.com'}
]
});
Ext.create ('Ext.grid.Panel', {
title: 'example1',
store: Ext.data.StoreManager.lookup('example1'),
columns: [
{header: 'Name', dataIndex: 'name', flex: 1},
{header: 'Email', dataIndex: 'email', flex: 1}
],
renderTo: Ext.getBody()
});
}
}))
网格可以按照用户需求定制的方式进行配置
如果您有使用Ext.panel.panel和表布局的特定原因,可以使用XTemplate,但绑定数据会更复杂 Ext.grid.Panel控件是完全可配置的,因此它允许隐藏网格的不同部分。在本例中,隐藏标题的方法是添加属性:hideHeaders: Ext.create(“Ext.grid.Panel”{ 隐藏者:没错, 列:[……], …其他选择。。。 }); 如果您仍然想采用另一种解决方案,我考虑过的更复杂的解决方案是使用XTemplate动态构建表。(http://docs.sencha.com/ext-js/4-1/#!/api/Ext.XTemplate)。在这种方法中,您编写了描述如何构建表的模板
否则,我仍然建议您处理前一种解决方案,而不是后一种。后一种方法与Sencha ExtJS的基本思想相反:使用ExtJS库的小部件,以最灵活的方式自定义它们,然后通过创建存储和模型实现自动化。Ext.grid.Panel控件完全可配置,因此允许隐藏网格的不同部分。在本例中,隐藏标题的方法是添加属性:hideHeaders: E