PDA

View Full Version : load data into jsonstore



jomlim
26 Aug 2011, 5:25 AM
hi all:
var store = new Ext.data.JsonStore({
autoDestroy : true,
url : 'usersdata.js',
root : 'users',
idProperty : 'id',
totalProperty : 'total',
fields : fields
})

userdata.js code:
{
users : [{
id : 1,
name : "lin",
sex : "0",
number : "01"
}, {
id : 2,
name : "she",
sex : "1",
number : "02"
}]
}

after running ....the page just load one record . anybody know why?

fay
26 Aug 2011, 6:31 AM
Use Firefox + Firebug and take a look at what is being returned by usersdata.js in the console.

jomlim
26 Aug 2011, 6:48 AM
27713this is usersdata.js return

fay
26 Aug 2011, 6:55 AM
(Note, I'm assuming this is Ext 3.x as you're using JsonStore.)

Double-check that your store is valid: add a load handler, and using Firebug, put a BP in it, and examine the contents of "store".

When you say "the page just load one record" are you displaying this data in a grid? Have you double-checked the grid's config to see if it's correct?

jomlim
26 Aug 2011, 7:10 AM
27714just display the first record and the data of id is not display


function sex(value){
return "0"?"男":"女";
}
function add(){
alert("11");
}
function del(){
alert("22");
}
function edit(){
alert("33");
}
Ext.onReady(function() {
var cm = new Ext.grid.ColumnModel([{
header : "id",
dataIndex : id
}, {
header : "姓名",
dataIndex : "name"
}, {
header : "性别",
dataIndex : "sex",
renderer:sex
}, {
header : "编号",
dataIndex : "number"
}]);
var fields = ["id", "name", "sex", "number"]
// var data = [[6, 'lin', 'm', "01"], [3, 'lin', 'm', "01"]];
var store = new Ext.data.JsonStore({
autoDestroy : true,
url : 'usersdata.js',
root : 'users',
idProperty : 'id',
totalProperty : 'total',
fields : fields
})
var egrid = new Ext.grid.GridPanel({
title : "用户管理",
store : store,
cm : cm,
tbar:[{text:"添加",handler:add},{text:"删除",handler:del},{text:"编辑",handler:edit}],
bbar:new Ext.PagingToolbar({store:store,pagesize:5})
})
store.load();
egrid.render(document.body)
/*
* new Ext.Viewport({ layout : "fit", items : egrid });
*/
})

mberrie
27 Aug 2011, 7:33 PM
Please use CODE tags!

Problem is here:



var cm = new Ext.grid.ColumnModel([{
header : "id",
dataIndex : id
}

skirtle
30 Aug 2011, 3:58 AM
Agreed, that would explain the missing column.

As for the missing record, try setting a fixed height on the grid. It may well have both records but be too short to display them both.