首页技术文档Extjs › Extjs中JSonStore的操作

Extjs中JSonStore的操作

I’m trying to get a jsonstore to read in data and parse it. It sounds simple enough, but for whatever reason, I am having a heck of a time doing it. I’ve boiled down my problem to the simplest example I can think of, but I’m still not getting it. Any ideas?

Here is the code. The idea is that when you click on the button, the JSON is parsed and an alert pops up with the name field from the record.

When I step through the code using Firebug, the “each” function on the datastore steps right over the alert, acting as if there are no records.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>

<html>

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />

<title>Ext JSON example</title>

<script type=”text/javascript” src=”lib/ext/ext-2.0/adapter/ext/ext-base.js”></script>

<script type=”text/javascript” src=”lib/ext/ext-2.0/ext-all-debug.js”></script>

<script>

function example() {

var exampleData = {‘exampleJSON’ : {‘exampleArray’:[{'exampleID':1,'name':'Fred','description':'a guy'},{'exampleID':2,'name':'sue','description':'a girl'}]}};

var ExampleRecord = Ext.data.Record.create([

{name: 'exampleID',???????? type: 'int'},

{name: 'name',??????????????? type: 'string'},

{name: 'description',??????? type: 'string'}

]);

var exampleReader = new Ext.data.JsonReader({

root: “exampleData.exampleJSON.exampleArray”,

id? : “exampleID”

}, ExampleRecord);

var exampleStore = new Ext.data.JsonStore({

proxy: new Ext.data.MemoryProxy(exampleData),

reader: exampleReader

});

exampleStore.each(function(aRecord, anId) {

alert(“***DEBUG>name is: ” + aRecord.get(‘name’));

});

}

</script>

</head>

<body>

<center><button onclick=”example();”>Click for Example</button></center>

</body>

</html>

本站技术交流群:24735919,欢迎大家进群交流探讨!

2 Comments.[ Leave a comment ]

  1. 阅读相当有难度啊,更何况偶还要读懂。

发表评论