开发者

XMLReader Problem In Sencha Touch

开发者 https://www.devze.com 2023-02-25 11:03 出处:网络
Dear All, I Have Datas in XML (users.xml, it\'s from sencha docs example) <?xml version=\"1.0\" encoding=\"UTF-8\"?>

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>ed@sencha.com</email>
</user>
<user>
    <id>2</id>
    <name>Abe Elias</name>
    <email>abe@sencha.com</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 sto开发者_如何学运维re = 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


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).

store.load();

Or you could add an autoload variable to the store itself;

var store = new Ext.data.Store({
    model: 'User',
    proxy: {
        type: 'ajax',
        url : 'users.xml',
        reader: {
            type: 'xml',
            record: 'user'
        }
    }, 
    autoLoad: true
});
0

精彩评论

暂无评论...
验证码 换一张
取 消