当我使用RESTJSON时,ExtJS6网格显示为空
使用ExtJS6.20CE,经典 我的网格显示为空 我尝试使用硬编码的数据存储,效果很好,但当我尝试从RESTURL获取JSON格式的数据时,它不起作用当我使用RESTJSON时,ExtJS6网格显示为空,json,rest,extjs,extjs6-classic,Json,Rest,Extjs,Extjs6 Classic,使用ExtJS6.20CE,经典 我的网格显示为空 我尝试使用硬编码的数据存储,效果很好,但当我尝试从RESTURL获取JSON格式的数据时,它不起作用 var dataStore; //Datos de tabla var grid; // objeto de tabla function cargaInicial() { crearGrid(); cargarVentana(); } function cargarVentana() { var win = ne
var dataStore; //Datos de tabla
var grid; // objeto de tabla
function cargaInicial() {
crearGrid();
cargarVentana();
}
function cargarVentana() {
var win = new Ext.create('Ext.Window', {
id : 'ventanaTarificador',
title : 'Tarificador',
layout : 'fit',
maximized: true,
closable: false,
resizable:true,
items:[grid]
});
win.show();
}
function crearGrid() {
Ext.define('lineaTarificador', {
extend: 'Ext.data.Model',
fields: ['pais', 'tomador', 'asegurado', 'divisa','a','b','c','d','e','f','g','h','i','j']
});
dataStore = Ext.create('Ext.data.Store', {
storeId: 'tarifStore',
Model: 'lineaTarificador',
fields:[ 'pais', 'tomador', 'asegurado', 'divisa','a','b','c','d','e','f','g','h','i','j'],
groupField: 'pais',
proxy: {
type: 'rest',
url: 'rest/Items',
reader: {
dataType: 'json',
rootProperty: 'data'
}
}
});
grid = Ext.create('Ext.grid.Panel', {
title: 'tarificadorGrid',
id: 'tarificadorGrid',
store: dataStore,
columns: [
{ text: 'Pais', dataIndex: 'pais', locked: true, width:80},
{ text: 'Tomador', dataIndex: 'tomador', locked: true, autoSizeColumn: true, width:200 },
{ text: 'Actividad', dataIndex: 'tomador', align: 'center', locked: true, width:40},
{ text: 'Divisa', dataIndex: 'divisa' , locked: true, width:45},
{ text: 'Asegurado', dataIndex: 'asegurado', locked: true, width:100},
{ text: 'Columna A', dataIndex: 'a', summaryType: 'sum' , width:150},
{ text: 'Columna B', dataIndex: 'b', summaryType: 'sum' , width:150},
{ text: 'Columna C', dataIndex: 'c', summaryType: 'sum' , width:150},
{ text: 'Columna D', dataIndex: 'd', summaryType: 'sum' , width:150},
{ text: 'Columna E', dataIndex: 'e', summaryType: 'sum' , width:150},
{ text: 'Columna F', dataIndex: 'f', summaryType: 'sum', width:150},
{ text: 'Columna G', dataIndex: 'g', summaryType: 'sum', width:150},
{ text: 'Columna H', dataIndex: 'h', summaryType: 'sum',width:150},
{ text: 'Columna I', dataIndex: 'i', summaryType: 'sum', width:150},
{ text: 'Columna J', dataIndex: 'j', summaryType: 'sum', width:150}
],
layout: 'fit',
features: [{ftype:'groupingsummary'}],
});
}
Ext.onReady(cargaInicial);
从该方向接收的数据为:
{“pais”:“Alemania”,“tomador”:“Terra”,“asegurado”:“Telefonica”,“divisa”:“USD”,“a”:
第10000.2节,b节:第10000.2节,c节:第10000.2节,d节:第10000.2节,e节:第10000.2节,f节:第10000.2节,g节:第10000.2节,h节:第10000.2节,i节:第10000.2节,j节:第10000.2节)
我做错了什么
提前感谢。您的
商店似乎根本没有加载,请尝试将cargaInicial()
编辑为以下内容:
function cargaInicial() {
crearGrid();
cargarVentana();
dataStore.load(); //load your store
}
或者使用configautoLoad:true
设置存储,如:
dataStore = Ext.create('Ext.data.Store', {
storeId: 'tarifStore',
Model: 'lineaTarificador',
fields: ['pais', 'tomador', 'asegurado', 'divisa', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'],
groupField: 'pais',
autoLoad:true,
proxy: {
type: 'ajax',
url: 'https://api.myjson.com/bins/8k1at',
reader: {
dataType: 'json',
rootProperty: 'data'
}
},
});
非常感谢。最后,问题是自动加载:true
和根属性:'data'
。现在工作得很好!