Sencha Touch XML解析问题 [英] Sencha Touch XML Parsing Issue

查看:188
本文介绍了Sencha Touch XML解析问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Sencha Touch框架的新手。我尝试使用文档来制作演示应用程序。我试图从XML文件中显示记录,并以表格格式显示。我不明白我在做错什么我正在屏幕顶部的Dock和空白页面。以下是我的代码



Index.js

  Ext.setup({
onReady:function(){

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

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


var list = new Ext.List({
fullscreen:true,

itemTpl :'{id} {name}',
分组:true,
indexBar:true,

store:store
});
列表。 show();

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

Users.xml

 <?xml version =1.0encoding =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>

请帮助我...提前感谢...

解决方案

首先,您将需要熟悉如何遍历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.

这篇关于Sencha Touch XML解析问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆