下面的代码正常工作正在加载数据MyData变量,但是需要从php中获取来自页面的数据,然后点击store feed the grid。 在我的页面php中,它生成一个代码json,并且ajax将其保存在可变数据中,在alert(javascript)中显示信息。
从现在开始,谢谢;
pdvs : function () {
$(document).ready(function () {
$.ajax({
url : "relpontovendaper.php",
dataType : "json",
success : function (data) {
alert(data[1].nome);
}
});
});
// return php [ { "nome": "Claudemir", "sobrenome": "Feliciano" }, { "nome": "Mario Borges" , "sobrenome": "Juno" } ]
var store = new Ext.data.JsonStore({
fields : ['name', 'area']
});
//This is Load.
var myData = [['Maria', 'santos'],
['Lucas', 'pereira'],
['Mariana', 'fagundes']];
var store = new Ext.data.SimpleStore({
fields : [
'nome',
'sobrenome'
]
});
// this load in grid
store.loadData(myData);
//this dont load in grid - informations of ajax in format json
store.loadData(data);
Ext.getCmp("_relpontoperiodo_grid").getStore().loadData(myData);
}
//This is a item (window)
items : [{
xtype : "grid",
id : "_relpontoperiodo_grid",
height : 230,
width : 200,
store : new Ext.data.SimpleStore({
fields : [
'nome',
'sobrenome'
]
}),
columns : [{
header : "PDV_COD",
sortable : true,
dataIndex : 'nome'
}, {
header : "PDV_DESCRIÇÃO",
sortable : true,
dataIndex : 'sobrenome',
flex : 1
}
]
}
]
答案 0 :(得分:1)
要远程检索data
(在本例中为php
),您可以向商店添加代理。这是一个例子:
var store = new Ext.data.JsonStore({
fields : ['name', 'area'],
autoLoad:true, //this will autoLoad the store on load. Or you can call
//store.load() later.
proxy: {
type: 'ajax',
url: 'relpontovendaper.php',
reader: {
type: 'json',
root: ''
}
}
});
答案 1 :(得分:0)
$(document).ready(function () {
$.ajax({
url : "/php/sge/relpontovendaper.php",
dataType : "json",
success : function (data) {
alert(data[1].nome);
//store.loadData(data);
Ext.getCmp("_relpontoperiodo_grid").getStore().loadData(data);
}
});
});