且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Sencha Touch XML解析问题

更新时间:2023-11-24 16:51:40

首先,您将需要熟悉如何遍历ST源代码并设置断点,以及如何在浏览器中查看控制台输出。 / p>

尝试这样:使用sencha-touch-debug.js而不是sencha.js。然后,使用您的开发人员控制台在Ext.data.Store类构造方法中设置一个断点。在构造函数方法的底部附近,您将看到以下代码:

 } else if(this.autoLoad){
Ext.defer(this.load,10,this,[typeof this.autoLoad =='object'?this.autoLoad:undefined]);
}

这是一个提示,你需要设置你的autoLoad属性数据存储对象。



一旦这样做,您将可以看到数据存储的加载功能被调用。



请注意,如果您使用Chrome并尝试加载HTML& XML文件本地(而不是Web服务器),您将遇到另一个问题,描述在[这个问题]。如果是这种情况,您将在您的JavaScript控制台中看到错误。


I am new to Sencha Touch framework. I tried using the Documentation to make a demo application. I am trying to display records from a XML file and display it in table format. I am not able to understand what I am doing wrong. I am getting the Dock at the top of the screen and a blank page. Below is my code

Index.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 : '{id} {name}',
        grouped : true,
        indexBar: true,

        store: store
    });
    list.show();

    var panel = new Ext.Panel({
        fullscreen: true,
        dockedItems:[
            {
                dock: 'top',
                xtype: 'toolbar',
                title: 'Users'
            }
        ]
    });
}
});

Users.xml

<?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>

Please help me... Thanks in advance...

First of all, you will want to get familiar with how to step through the ST source code and set breakpoints, and how to view console output in your browser.

Try this: use sencha-touch-debug.js instead of sencha.js. Then, use your developer console to set a breakpoint in the Ext.data.Store class constructor method. Down near the bottom of the constructor method, you will see the following code:

    } else if (this.autoLoad) {
        Ext.defer(this.load, 10, this, [typeof this.autoLoad == 'object' ? this.autoLoad : undefined]);
    }

This is a hint to you that you need to set the autoLoad attribute on your data store object.

Once you do that, you will be able to see that the datastore's "load" function is called.

Note that if you are using Chrome and trying to load the HTML & XML files locally (instead of from a webserver), you will run into another issue described in [this question]. You will see an error in your javascript console if this is the case.