Sencha Touch 中的 XMLReader 问题
亲爱的大家,我有 XML 数据(users.xml,来自 sencha 文档示例),
<?xml version="1.0" encoding="UTF-8"?>
<user>
<id>1</id>
<name>Ed Spencer</name>
<email>[email protected]</email>
</user>
<user>
<id>2</id>
<name>Abe Elias</name>
<email>[email protected]</email>
</user>
我想将这些数据加载到 sencha 列表中。这是我的 js 代码 (user.js)
Ext.setup({
onReady: function() {
Ext.regModel('User', {
fields: ['id', 'name', 'email']
});
var store = new Ext.data.Store({
model: 'User',
proxy: {
type: 'ajax',
url : 'users.xml',
reader: {
type: 'xml',
record: 'user'
}
}
});
var list = new Ext.List({
fullscreen: true,
itemTpl : '{name} {email}',
grouped : true,
indexBar: true,
store: store
});
list.show();
}
});
和我的 html 文件 (user.html)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="senchalib/resources/css/sencha-touch.css" type="text/css">
<script type="text/javascript" src="senchalib/sencha-touch.js"></script>
<script type="text/javascript" src="user.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>
仅供参考,这三个文件存储在同一个文件夹中。当我在谷歌浏览器中测试时,我没有得到任何数据。我的代码做错了什么吗?有人能指出我哪个代码是错误的吗?我已经在这个网站上搜索了类似的主题,但我仍然没有得到明确的答案。谢谢
Dear All, I Have Datas in XML (users.xml, it's from sencha docs example)
<?xml version="1.0" encoding="UTF-8"?>
<user>
<id>1</id>
<name>Ed Spencer</name>
<email>[email protected]</email>
</user>
<user>
<id>2</id>
<name>Abe Elias</name>
<email>[email protected]</email>
</user>
I want to load those datas in sencha list. It's my js code (user.js)
Ext.setup({
onReady: function() {
Ext.regModel('User', {
fields: ['id', 'name', 'email']
});
var store = new Ext.data.Store({
model: 'User',
proxy: {
type: 'ajax',
url : 'users.xml',
reader: {
type: 'xml',
record: 'user'
}
}
});
var list = new Ext.List({
fullscreen: true,
itemTpl : '{name} {email}',
grouped : true,
indexBar: true,
store: store
});
list.show();
}
});
and it's my html file (user.html)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="senchalib/resources/css/sencha-touch.css" type="text/css">
<script type="text/javascript" src="senchalib/sencha-touch.js"></script>
<script type="text/javascript" src="user.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
</body>
</html>
FYI, thos three files are stored in the same folder. When i test in google chrome, i got no datas. did i do something wrong with my code? could somebody point me which code is wrong? i have searced the similar topic in this site but i still get no clear answer. thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己是 Sencha Touch 的新手。但我已经启动并运行了一个类似的解决方案(尽管我的脚本使用 JSON 而不是 XML)。
当我浏览您的代码时,看起来您从未启动过商店的加载。商店永远不会“启动”。
您可以使用(与代码中的 .show(); 大致相同的行)强制加载存储。
或者您可以向存储本身添加一个自动加载变量;
I'm new to Sencha Touch myself. But I have got a similar solution up and running (although my script uses JSON instead of XML).
As I browse through your code it looks like you never initiate a load of the store. The store nevers 'starts'.
You can force a load of the store by using (at roughly the same line as .show(); in your code).
Or you could add an autoload variable to the store itself;