首页 \ 问答 \ Sencha Touch读取XML数据(Sencha Touch Reading XML data)

Sencha Touch读取XML数据(Sencha Touch Reading XML data)

我刚刚开始使用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'
            }


            ]
        });
    }
});

I have just recently started working with Sencha Touch 2.0. I am having problem in reading XML data. I started with basic "getting started" app which comes with the download and it is working fine which means I have done the setup correctly. Now I have made some changes to read simple XML but I am not able to see any data on screen. Below is my code. Please help me with this. - here are the contents of app.js file -

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                    
                }


            ]
        });
    }
});

The XML is at the same location as this app.js file. Please note that I have not installed any server. I just make changes to app.js and open "index.html" in chrome browser.

Here is the XML. It is same as the one given on 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>

Here is my code after changes -

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'
            }


            ]
        });
    }
});

原文:https://stackoverflow.com/questions/11062233
更新时间:2024-03-19 18:03

最满意答案

对于初学者,您可以添加一个Book实体,该实体与Page和Note有很多关系。 你也可以像-pageForPageNumber:-notesForPage:一样添加方法-notesForPage:只是为了方便你访问你可能需要的东西。 如果您的应用程序代表一本书,那么您可以拥有一些适当的类,例如您的应用程序委托或您的根视图控制器在商店中获取Book的一个实例。 如果您的应用程序更像是包含多本书籍的阅读器,您可以首先获取所有书籍并将其显示在列表中,以便用户可以选择一本书籍。


For starters, you might add a Book entity which has to-many relationships with Page and Note. You could also add methods to Book like -pageForPageNumber: and -notesForPage: just to make it easy to access the things you're likely to need. If your app represents a single book, then you can have some appropriate class like your app delegate or your root view controller fetch the one instance of Book in the store. If your app is more like a reader that contains multiple books, you might instead start by fetching all the books and displaying them in a list so that the user can choose one.

相关问答

更多
  • 尝试在没有“。”的情况下重命名您的关系。 通常的模式是例如对于一对一关系的“authorName”和对于多对多关系的“authorNames”。 Try renaming your relationships without "."s. The usual pattern is e.g. "authorName" for a to-one relationship and "authorNames" for a to-many relationship.
  • 我通过创建一个对象,设置它的属性,然后在数组控制器上调用addObject:id来对此进行排序。 希望这有助于某人。 I sorted this by creating an object, setting it's properties, then calling addObject:id on the array controller. Hope this helps someone.
  • 好吧,“虚拟指数”方式在时尚之后起作用 知道了我的字典数组中每个对象的位置(索引),我能够在用适当的数据加载我的实体后设置所需的关系。 顺便说一句,对于试图完成同样事情的人来说,这是我采取的程序: 在XCode中创建一个新的PLIST文件(文件 - >新建 - >文件 - > IOS资源 - >属性列表) 填充PLIST: 在Root下,为我的数据模型中的每个实体添加了一个ARRAY项。 在每个ARRAY中,为每个实体对象添加了一个DICTIONARY项。 在每个DICTIONARY中,添加了反映属性NAM ...
  • 看看实现类方法keyPathsForValuesAffecting 链接 Have a look at implementing the class method keyPathsForValuesAffecting Link
  • 在Apple使用MVC习惯用语的环境中,核心数据本身绝对可以用于整个数据层。 托管对象子类可以包含许多功能 - 您称之为模型“逻辑”。 这是一种非常常见的设计模式。 例如,如果您的数据模型使用美元值描述事务数据,则可以使用提取请求模板来提供这些值的总和。 您可以通过使用提供计算/格式化数据的自定义方法扩展托管对象来执行更复杂的操作。 然后,在您的控制器中,您可以读取和更改数据,并从UI获取输入并更新数据的显示。 你的控制器不应该做更多的事情。 当然,在极其复杂的应用程序逻辑的情况下,您始终可以创建像Deri ...
  • SyncML规范可能有帮助,但很难阅读,而且显然偏向于SyncML。 我必须为Task Coach实现这个功能,所以这里有一些想法: 修改标志就足够了,时间戳并不能提供更多的信息。 通常,我的对象处于以下状态之一: 没有 新 删除 改性 对象被修改时发生以下转换: 无 - >修改 新 - >新 已删除 - >(不应该发生) 修改 - >修改 以及下列情况: 无 - >删除 新建 - >实际删除(可能会从存储中删除) 已删除 - >(不应该发生) 修改 - >删除 同步时,设备首先向桌面发送状态不是“无”的所 ...
  • TL; DR - 不要这样做或事情会破裂。 过去有各种各样的黑客让它进行某种工作,但它们都依赖于CoreData中的无证行为。 我绝对不会在代码中使用类似的东西,我想展示另一个人,更不用说给客户发货了。 CoreData需要插入挂钩到模型对象上的属性更改事件的 代理对象 ,并且它能够可靠地执行此操作并跟踪原始数据值的唯一方法是,它是否负责首先创建这些实体; 这也使得错误和分配系统的工作。 不要将Core Data视为ORM,它实际上是一个对象图管理框架 ,因此它被设计为以某种方式使用而没有简单的解决方案来安 ...
  • 您应该使用公共字段创建一个抽象实体,并从那里继承您的不同合同类型。 从文档 : 在模型中,实体可以布置在继承层次结构中,实体可以指定为抽象。 这还使您能够为所有合同定义常见行为,并使用代码中的抽象超类来引用任何合同。 You should create an abstract entity with your common fields, and inherit your different contract types from there. From the documentation: In a mo ...
  • 此信息存储在数据模型文件中。 没有要跟踪的单独文件,它与实体定义位于同一文件中。 但是Xcode并不总是保留这些数据。 这是一个错误。 我早已放弃了图表视图,部分原因是当Xcode丢失排列并将所有实体放在图表的中心时,我不得不经常清理它。 提交错误,并停止使用图表视图。 这是保持理智的最佳方式。 This information is stored in the data model file. There's no separate file to track, it's in the same file ...
  • 对于初学者,您可以添加一个Book实体,该实体与Page和Note有很多关系。 你也可以像-pageForPageNumber:和-notesForPage:一样添加方法-notesForPage:只是为了方便你访问你可能需要的东西。 如果您的应用程序代表一本书,那么您可以拥有一些适当的类,例如您的应用程序委托或您的根视图控制器在商店中获取Book的一个实例。 如果您的应用程序更像是包含多本书籍的阅读器,您可以首先获取所有书籍并将其显示在列表中,以便用户可以选择一本书籍。 For starters, you ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)