简体   繁体   中英

Sencha Touch - XML Reader issue

I am trying some basic application on Sencha Touch 2.

Instead of json , I am trying to read an xml in the sencha touch list.

I have my store defined like this,

 Ext.define('MyApp.store.ListStore', {
    extend: 'Ext.data.Store',

    config: {
        fields: ['id','name','email'],
        proxy: {
           type: 'jsonp',
           url: 'users.xml',
           reader: {
              type: 'xml',
              record: 'user',
              rootProperty: 'users'
           }
        },
        autoLoad:true,
    }
});

and my xml file is located at the same place where my store is.

 <?xml version="1.0" encoding="UTF-8"?>
<users>
    <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>
</users>

and my list view goes like this,

var listStore = Ext.create('MyApp.store.DStore');

Ext.define('MyApp.view.NavigateView', {
    extend: 'Ext.navigation.View',
    xtype: 'navigateview',

    requires: [
        'MyApp.store.ListStore'
    ],
    config: {
        fullscreen: true,
        scrollable: true,

        items: [
            {
                  xtype: 'list',
                  title: 'List',
                  id: 'datalist',
                  onItemDisclosure: true,
                  store: listStore,
                  itemTpl: '<div class="contact">{name}</div>',
            }
         ]
     }
});

but no o/p is shown.

Where am I doing wrong ? Please suggest!

Couple issues. Your XML is not valid, it needs to be like

<?xml version="1.0" encoding="UTF-8"?>
<users>
    <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>
</users>

The other issue is you shouldn't create your store like that. Either specify it in the stores array and refer to it via the store id in your list or create the store like:

store : {
    xclass : 'MyApp.store.ListStore'
}

Also, I have an eye for extra commas... bad extra comma! It's at the end of autoLoad : true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM