gpt4 book ai didi

javascript - ExtJs4 网格不显示响应中的数据

转载 作者:行者123 更新时间:2023-12-02 17:50:48 24 4
gpt4 key购买 nike

我正在尝试使用 Sencha 的 ExtJs 4.2 来排列基于 ajax 的网格。我定义了数据模型和自定义网格组件,但不幸的是它无法显示接受的数据。我不知道为什么:(

型号代码:

Ext.define('OperatedClient', {
extend: 'Ext.data.Model',
fields: [
{name: 'id'},
{name: 'first_name'},
{name: 'second_name'},
{name: 'surname'},
{name: 'birthdate'},
{name: 'diagnose'},
{name: 'operation_date'},
{name: 'operation'},
{name: 'price'}
]
});

我的网格组件代码:

var defaultColumnRenderer = function(v) {
return '<div style="text-align:right">' + v + '</div>';
};

Ext.define('Ext.custom.OperatedClientsGrid', {
extend: 'Ext.grid.Panel',
cls: 'custom-grid',
columnLines: true,
initComponent: function() {
var opStore = Ext.create('Ext.data.Store', {
autoLoad: true,
model: 'OperatedClient',
proxy: Ext.create('Ext.data.proxy.Ajax', {
url: 'service/clients_op/read.php',
reader: Ext.create('Ext.data.reader.Json', {
root: '$client_ops'
})
})
});
Ext.apply(this, {
store: opStore
},
columns: [{
text: 'Id',
dataIndex: 'id',
align: 'center',
renderer: defaultColumnRenderer
},{
text: 'Имя',
dataIndex: 'first_name',
align: 'center',
renderer: defaultColumnRenderer
},{
text: 'Отчество',
dataIndex: 'second_name',
align: 'center',
renderer: defaultColumnRenderer
},{
text: 'Фамилия',
dataIndex: 'surname',
align: 'center',
renderer: defaultColumnRenderer
},{
text: 'Дата рождения',
dataIndex: 'birthdate',
align: 'center',
renderer: defaultColumnRenderer
},{
text: 'Диагноз',
dataIndex: 'diagnose',
align: 'center',
renderer: defaultColumnRenderer
},{
text: 'Операция',
dataIndex: 'operation',
align: 'center',
renderer: defaultColumnRenderer
},{
text: 'Дата операции',
dataIndex: 'operation_date',
align: 'center',
renderer: defaultColumnRenderer
},{
text: 'Стоимость',
dataIndex: 'price',
align: 'center',
renderer: defaultColumnRenderer
}]
});
this.callParent();
}
});

服务器响应代码:

{"client_ops":[{"id":"1","first_name":"\u0410\u043d\u0434\u0440\u0435\u0439","second_name":"\u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447","surname":"\u0411\u043e\u043b\u044f\u0447\u043a\u0438\u043d","diagnose":"\u041f\u0438\u0437\u0434\u0430\u0440\u0438\u043a\u0438","operation_date":"2014-01-21","operation":"\u041e\u0431\u0440\u0435\u0437\u0430\u043d\u0438\u0435","price":"3000"},{"id":"2","first_name":"\u0410\u0440\u043a\u0430\u0434\u0438\u0439","second_name":"\u0418\u043c\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432\u0438\u0447","surname":"\u0416\u0438\u043b\u0438\u0441\u0442\u044b\u0439","diagnose":"\u041f\u043e\u0435\u0431\u0443\u0448\u0435\u0447\u043a\u0438","operation_date":"2014-01-25","operation":"\u041e\u0431\u0435\u0437\u0433\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u043d\u0438\u0435","price":"1500"},{"id":"3","first_name":"\u0411\u043e\u0440\u0438\u0441","second_name":"\u0412\u0438\u0442\u0430\u043b\u044c\u0435\u0432\u0438\u0447","surname":"\u0422\u0440\u0430\u043a\u0442\u043e\u0440","diagnose":"\u041a\u043e\u0441\u043e\u0451\u0431\u0438\u0435","operation_date":"2014-11-23","operation":"\u041f\u0440\u043e\u0442\u0435\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435","price":"4700"},{"id":"4","first_name":"\u0421\u0435\u0440\u0433\u0435\u0439","second_name":"\u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447","surname":"\u041a\u0430\u0440\u0442\u043e\u0448\u0438\u043d","diagnose":"\u0424\u0413\u041c","operation_date":"2014-01-20","operation":"\u0412\u0441\u043a\u0440\u044b\u0442\u0438\u0435","price":"8700"}]}

抱歉,如果它太大且笨拙,但我认为响应包含映射到声明的模型字段的所有必要参数。有人看出我的错误在哪里吗?

最佳答案

正如评论中所述,您的 root 不正确,应该是 client_ops。顺便说一句,您不需要直接创建对象的实例,您可以像这样声明您的商店:

Ext.define('Ext.custom.OperatedClientsGrid', {
extend: 'Ext.grid.Panel',
cls: 'custom-grid',
columnLines: true,
initComponent: function() {
this.store = {
model: 'OperatedClient',
proxy: {
type: 'ajax',
reader: {
root: 'client_ops'
}
}
};
this.columns = [];
}
});

建议@Akatum作为答案发布,请不要接受,因为@Akatum已经发布了解决方案,我只是想提一下侧面的观点,但它太长了,无法发表评论。

关于javascript - ExtJs4 网格不显示响应中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21370004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com