Sencha Touch XML 列表

发布于 2025-01-01 01:41:36 字数 1203 浏览 4 评论 0原文

您好,我有一个关于 Sencha Touch 的 XML 列表的问题。

我在 Sencha Touch 中加载一些 XML,我想将它们显示为列表:

这是我的代码: Sencha:

Ext.setup({  
onReady: function() {   
Ext.regModel('navModel', {
  fields: [
       {name:'id'},
       {name:'title'}
       ]
});

var navi = new Ext.data.Store({
    autoLoad:true,
    model: 'navModel',
    method: 'POST',
    proxy: {
    type: 'ajax',
    url : 'navi.xml',
    reader: {
    type : 'xml',
root: 'menu',
record:'navigation'
 }
}  
});
   var something = new Ext.List({
        store: 'navi',
        title: 'asdfasdf',
        emptyText: 'No data',
        fulscreen: true,
        itemTpl: '{id} - {title}'
    });


       var rootPanel = new Ext.TabPanel({
            fullscreen:true,
            items:[something]
        }); 

    }

});

XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <menu>
    <navigation>
    <id>1</id>
    <title>Hello</title>
    </navigation>
    <navigation>
    <id>2</id>
    <title>Test</title>
    </navigation>
   </menu>

我可以读取 XML,但它没有在列表中显示它..出了什么问题?

感谢您的回答

Hei i have a Question about XML Lists with Sencha Touch.

I load some XML in Sencha Touch and i would like to display them as a List:

Here's my Code:
Sencha:

Ext.setup({  
onReady: function() {   
Ext.regModel('navModel', {
  fields: [
       {name:'id'},
       {name:'title'}
       ]
});

var navi = new Ext.data.Store({
    autoLoad:true,
    model: 'navModel',
    method: 'POST',
    proxy: {
    type: 'ajax',
    url : 'navi.xml',
    reader: {
    type : 'xml',
root: 'menu',
record:'navigation'
 }
}  
});
   var something = new Ext.List({
        store: 'navi',
        title: 'asdfasdf',
        emptyText: 'No data',
        fulscreen: true,
        itemTpl: '{id} - {title}'
    });


       var rootPanel = new Ext.TabPanel({
            fullscreen:true,
            items:[something]
        }); 

    }

});

XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <menu>
    <navigation>
    <id>1</id>
    <title>Hello</title>
    </navigation>
    <navigation>
    <id>2</id>
    <title>Test</title>
    </navigation>
   </menu>

I can read the XML but it doesn't display it in the List.. what's wrong??

Thx for Answers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

z祗昰~ 2025-01-08 01:41:36

尝试将 TabPanel 更改为 Container,也许对您有帮助!

Try to change the TabPanel to Container, that maybe help you!

肥爪爪 2025-01-08 01:41:36

您必须写出商店名称,不带引号。

对于所有遇到映射问题的人...

您必须在 sencha-touch.js 的末尾添加此解决方法:

Ext.override( Ext.data.XmlReader, {
    createAccessor: function() {
        var selectValue = function(key, root, defaultValue){
            if( key == '#' ){
                return root.tagName;
            }
            if( key.indexOf( '@' ) != -1 ){
                var property = key.split( '@' )[ 1 ];
                key = key.split( '@' )[ 0 ];
            }
            var val;
            if( key.length ){
                var node = Ext.DomQuery.selectNode(key, root);
                if( node && node.firstChild ){
                    node = node.firstChild;
                }
            }
            else{
                var node = root;
            }
            if(node){
                if( typeof( node.getAttribute ) != 'undefined' && typeof( property ) != 'undefined' ){
                    val = node.getAttribute( property );
                }
                else{
                    val = node.nodeValue;
                }
            }
            return Ext.isEmpty(val) ? defaultValue : val;
        };

        return function(key) {
            var fn;

            if (key == this.totalProperty) {
                fn = function(root, defaultValue) {
                    var value = selectValue(key, root, defaultValue);
                    return parseFloat(value);
                };
            }

            else if (key == this.successProperty) {
                fn = function(root, defaultValue) {
                    var value = selectValue(key, root, true);
                    return (value !== false && value !== 'false');
                };
            }

            else {
                fn = function(root, defaultValue) {
                    return selectValue(key, root, defaultValue);
                };
            }

            return fn;
        };
    }(),
});

这样您就可以使用“@attributename”访问 xml 的属性

,并且如果您想访问你写的子属性“childname@attributename”

我希望我能帮助你..为此搜索了几个小时..;)

You have to write the name of the store without the quote sign.

And for all who got problems with mapping...

you have to add this workaround on the end of sencha-touch.js:

Ext.override( Ext.data.XmlReader, {
    createAccessor: function() {
        var selectValue = function(key, root, defaultValue){
            if( key == '#' ){
                return root.tagName;
            }
            if( key.indexOf( '@' ) != -1 ){
                var property = key.split( '@' )[ 1 ];
                key = key.split( '@' )[ 0 ];
            }
            var val;
            if( key.length ){
                var node = Ext.DomQuery.selectNode(key, root);
                if( node && node.firstChild ){
                    node = node.firstChild;
                }
            }
            else{
                var node = root;
            }
            if(node){
                if( typeof( node.getAttribute ) != 'undefined' && typeof( property ) != 'undefined' ){
                    val = node.getAttribute( property );
                }
                else{
                    val = node.nodeValue;
                }
            }
            return Ext.isEmpty(val) ? defaultValue : val;
        };

        return function(key) {
            var fn;

            if (key == this.totalProperty) {
                fn = function(root, defaultValue) {
                    var value = selectValue(key, root, defaultValue);
                    return parseFloat(value);
                };
            }

            else if (key == this.successProperty) {
                fn = function(root, defaultValue) {
                    var value = selectValue(key, root, true);
                    return (value !== false && value !== 'false');
                };
            }

            else {
                fn = function(root, defaultValue) {
                    return selectValue(key, root, defaultValue);
                };
            }

            return fn;
        };
    }(),
});

so you can access the attribute of your xml with '@attributename'

and if you want to have access to the child attributes you write 'childname@attributename'

I hope i helped you.. searched some hours for this.. ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文