1

我最近才开始使用 Sencha Touch 2.0。我在读取 XML 数据时遇到问题。我从下载附带的基本“入门”应用程序开始,它运行良好,这意味着我已正确完成设置。现在我做了一些更改来读取简单的 XML,但我无法在屏幕上看到任何数据。下面是我的代码。请帮我解决一下这个。- 这里是 app.js 文件的内容 -

Ext.Loader.setPath({
    'Ext': 'lib/touch/src'
});

Ext.define('User', {
    extend: 'Ext.data.Model',
    config: {
        fields: ['id', 'name', 'email']
    }
});

var mystore = Ext.create('Ext.data.Store', {
    model: 'User',
    autoLoad: true,
    proxy: {
        type: 'ajax',
        url : 'userData.xml',
        reader: {
            type: 'xml',
            rootProperty: 'users',
            record: 'user'
        }
    }
});  

Ext.application({
    name: 'Sencha',

    launch: function() {
        //The whole app UI lives in this tab panel
        Ext.Viewport.add({
            xtype: 'tabpanel',
            fullscreen: true,
            tabBarPosition: 'bottom',   
            items: [
                // This is the home page, just some simple html
                {
                    title: 'Home',
                    iconCls: 'home',
                    cls: 'home',
                    scrollable: true,
                    html: [
                        '<img height=260 src="http://staging.sencha.com/img/sencha.png" />',
                        '<h1>Welcome to Sencha Touch</h1>',
                        "<p>Building the Getting Started app</p>",
                        '<h2>Sencha Touch (2.0.0)</h2>'
                    ].join("")
                },


                {
                    xtype: 'list',
                    title: 'Events',
                    iconCls: 'star',
                    itemTpl: '{id}',                     
                    store: mystore                    
                }


            ]
        });
    }
});

XML 与此 app.js 文件位于同一位置。请注意,我没有安装任何服务器。我只是对 app.js 进行更改并在 chrome 浏览器中打开“index.html”。

这是 XML。它与 Sencha Docs 上给出的相同。-

<?xml version="1.0" encoding="UTF-8"?>
<users>
<user>
    <id>112</id>
    <name>Ed Spencer</name>
    <email>ed@sencha.com</email>
</user>
<user>
    <id>248</id>
    <name>Abe Elias</name>
    <email>abe@sencha.com</email>
</user>
</users>

这是我更改后的代码 -

Ext.Loader.setPath({
    'Ext': 'lib/touch/src'
});


Ext.regModel('Personal', {
    fields  : [
        'id',
            {name: 'name',  type: 'string'}, 
            {name: 'email', type: 'string'}
    ]
});


Ext.application({
    name: 'Sencha',

    launch: function() {
        //The whole app UI lives in this tab panel
        Ext.Viewport.add({
            xtype: 'tabpanel',
            fullscreen: true,
            tabBarPosition: 'bottom',   
            items: [
                // This is the home page, just some simple html                                                

            {
                xtype   : 'selectfield',
                name    : 'user',
                label   : 'Users',
                store   : new Ext.data.Store({
                            model       : 'Personal',
                            autoLoad    : true,
                            proxy       : {
                                type    : 'ajax',
                                url     : 'userData.xml',
                                reader  : {
                                    type    : 'xml',
                                    root    : 'users'
                                }
                            }
                        }),
                valueField  : 'name',
                displayField    : 'name'
            }


            ]
        });
    }
});
4

2 回答 2

0

嘿@GordanWebb 试试这个来显示来自 XML 文件的数据,

Ext.regModel('Personal', {
    fields  : [
        'id',
            {name: 'name',  type: 'string'}, 
            {name: 'email', type: 'string'}
    ]
}), {
        scroll  : 'vertical',
        items   : [
            {
                xtype   : 'selectfield',
                name    : 'user',
                label   : 'Users',
                store   : new Ext.data.Store({
                            model       : 'Personal',
                            autoLoad    : true,
                            proxy       : {
                                type    : 'ajax',
                                url     : 'userData.xml',
                                reader  : {
                                    type    : 'xml',
                                    root    : 'users'
                                }
                            }
                        }),
                valueField  : 'name',
                displayField    : 'name',
            }
        ]
    }

此示例显示selectfield元素 Sencha 的数据。我希望这有帮助。:)

于 2012-06-16T15:51:40.670 回答
0

您只需要使用 Web 服务器(easyphp 或 wamp)(Linux 和 MacOS 上的 xamp)并访问您的应用程序抛出 localhost/yourAppDirectory,一切都会好起来的

于 2012-12-03T20:33:04.493 回答