1

次のxmlを解析して(ローカルマシンでホストした後)、ロードして保存しようとしています。

<?xml version="1.0" encoding="UTF-8"?>
<users>
    <user>
       <id>2</id>
       <name>shameel</name>
       <post>
         <user_id>5</user_id>
         <title>programmer</title>
         <body>nothing</body>
       </post>
       <post>
         <user_id>6</user_id>
         <title>newpost</title>
         <body>congrats</body>
       </post>
    </user> 
<user>
       <id>3</id>
       <name>abdulls</name>
       <post>
         <user_id>5</user_id>
         <title>programmer1</title>
         <body>nothing1</body>
       </post>
       <post>
         <user_id>6</user_id>
         <title>newpost1</title>
         <body>congrats1</body>
       </post>
       <post>
         <user_id>7</user_id>
         <title>newpost1</title>
         <body>congrats1</body>
       </post>
    </user>       
</users>

使用機種は以下の通りです。

Ext.define("SectionModel", {
            extend : 'Ext.data.Model',
            config : {
                fields : [{
                            name : 'section',
                            type : 'string',
                            mapping : '@section'
                        }],
                proxy : {
                    type : 'ajax', 

                     url : 'http://localhost:8080/sample1.xml', //sample1.xml is the file

                    reader : {
                        type : 'xml',
                        rootProperty : 'configs',
                        record : 'navigation'
                    }
                },

                hasMany : [{
                    model : 'ArticlesModel',
                    name : 'articlesModel',
                         associationKey:'sections'

                    }]



            }
        });










Ext.define("ArticlesModel", {
            extend : 'Ext.data.Model',
            config : {
                fields : [{
                        name : 'title',
                        type : 'string',
                        mapping : '@title'
                    }, {
                        name : 'value',
                        type : 'string',
                        mapping : '@value'
                    }],

                    proxy : {
                    type : 'ajax',
                                        url : 'http://localhost:8080/sample1.xml', //sample1.xml is the file
                    reader : {
                        type : 'xml',
                        rootProperty : 'navigation',
                        record : 'section'
                    }
                },

                belongsTo : 'SectionModel'


            }
        });

以下のように使用されるストア:

Ext.define("SectionStore", {
            extend : 'Ext.data.Store',

            config : {
                model : 'SectionModel',
                autoLoad : 'true'



            }
        });

以下のようにコンテンツにアクセスしようとします:

var store = Ext.data.StoreManager.get('SectionStore');
        if (!store) {
            console.log("Store not found");
            return;
        }

store.load(function(records, operation, success) {
                    for (var i = 0; i < store.getCount(); i++) {
                        var section_title = store.getAt(i).get('section');
                                                var subsection_val = store.getAt(i).articlesModel().get('title');//this function fails saying no "get" function for the object
}
});

ここで、section_title を取得できます。ただし、subsection_val を取得できません。ストア内のプロキシでこれを試しましたが、修正できませんでした。誰でも助けてください。

4

1 に答える 1

0

ネストされた XML 要素の解析で同様の問題に遭遇しました。残念ながら、XML 解析のコードを何度もハッキングした後、最終的にあきらめました。(最終的には、応答を JSON に変換する Web サービスへのパススルーを作成しました)

ここで私の(失敗した)冒険について読むことができます:

http://www.sencha.com/forum/showthread.php?189537-Sencha-Touch-2.0-nested-XML-parsing

于 2012-07-18T20:19:40.333 に答える