无法解析嵌套的JSON完全Sencha

时间:2013-07-11 09:52:16

标签: json sencha-touch-2

我的输出 ![我的输出] [1]

我一直在尝试从网址解析嵌套的json,但我无法完全解析它,我已查看可用的所有链接: link1 link2 link3 link4

这是我的previous question

我的json是

({
"accountInfo": {
    "expire_date": "2014-07-02 08:01:09",
    "subscribe_date": "2013-07-02 08:01:09",
    "time_remain": " 355 Days 20 Hours 47 Minutes",
    "status": "not expired"
},
"status": "TRUE",
"message": "Todays Word",
"data": [
    {
        "name": "abacus",
        "author": "admin",
        "word_id": "2",
        "category": "Education",
        "definitions": [
            {
                "rating": "Green",
                "defintion": "replace \"my pc\" asdf edited",
                "def_id": "53",
                "example": null,
                "author": "admin"
            },
            {
                "rating": "This definition is not rated yet.",
                "defintion": "my new definition of word abacus",
                "def_id": "7",
                "example": null,
                "author": "admin"
            },
            {
                "rating": "This definition is not rated yet.",
                "defintion": "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea, tempore labore veritatis maxime beatae est incidunt consectetur adipisci dolore reiciendis. Nostrum fugiat cumque beatae voluptatum.",
                "def_id": "45",
                "example": null,
                "author": "admin"
            },
            {
                "rating": "This definition is not rated yet.",
                "defintion": "this sub def will rep abacus' \"venture capitalist\"",
                "def_id": "31",
                "example": null,
                "author": "admin"
            }
        ],
        "is_favourite": "Yes"
    }
]
})

我的模特是

Ext.define('Sencha.model.Menu', {
extend: 'Ext.data.Model',
config: {
    fields: [
        'name',
        'author',
        'word_id',
        'category',
      'data.definitions.definition'
    ],

    belongsTo: "Sencha.model.Contact"
}
});

Ext.define('Sencha.model.Contact', {
extend: 'Ext.data.Model',

requires: ['Sencha.model.Menu'],

config: {
    fields: [
        {name: 'status', mapping: 'status'},
        {name: 'message', mapping: 'message'},
        {name:'data', mapping: 'data'},
        {name: 'definitions', mapping: 'definitions.defintion'},
        {name: 'ratings', mapping: 'definitions.rating'},
       /* {name: 'definition', mapping: 'definitions'}*/
     /*{name: 'definition', mapping: 'data.definition.final_rating'}, json data     parsing My Favourite page and Today's word 65%*/


    ],
}
});

我的商店

Ext.define('Sencha.store.Contacts', {
extend: 'Ext.data.Store',

config: {
    model: 'Sencha.model.Contact',
    autoLoad: true,
    //sorters: 'name',
    grouper: {
        groupFn: function(record) {
            return record.get('name')[0];
        }
    }
}
});

我的观点

Ext.define("Sencha.view.Main", {
extend: 'Ext.tab.Panel',
requires: ['Ext.TitleBar', 'Sencha.view.Contacts'],

config: {
    tabBarPosition: 'bottom',

    items: [
        {
            title: 'Contacts',
            iconCls: 'home',

            xtype: 'contacts'
        }
    ]
}
});

![i have been able to do upto this][7]
Ext.define('Sencha.view.Contacts', {
extend: 'Ext.List',
xtype: 'contacts',

config: {
    title: 'Stores',
    cls: 'x-contacts',

    store: 'Contacts',
    itemTpl: [

        '<div>',
            '<h2><b>Hello</b></h2>',
            '<tpl for="data">',
                '<div> - {name}</div>',
                '<div> - {author}</div>',
                '<div> - {word_id}</div>',
                '<div> - {category}</div>',
               '<div> - {definitions}</div>',

            '</tpl>',
        '</div>'
    ].join('')
}
});

我的输出应该是 ![在此输入图像说明] [8]

2 个答案:

答案 0 :(得分:1)

我不确定您到底想要实现的目标,我在本地重建您的应用程序并能够获得此屏幕:

screenshot

我认为我做的唯一重大改变是json:

    [
    {
        "accountInfo": {
            "expire_date": "2014-07-02 08:01:09",
            "subscribe_date": "2013-07-02 08:01:09",
            "time_remain": " 355 Days 20 Hours 47 Minutes",
            "status": "not expired"
        },
        "status": "TRUE",
        "message": "Todays Word",
        "data": [
            {
                "name": "abacus",
                "author": "admin",
                "word_id": "2",
                "category": "Education",
                "definitions": [
                    {
                        "rating": "Green",
                        "defintion": "replace \"my pc\" asdf edited",
                        "def_id": "53",
                        "example": null,
                        "author": "admin"
                    },
                    {
                        "rating": "This definition is not rated yet.",
                        "defintion": "my new definition of word abacus",
                        "def_id": "7",
                        "example": null,
                        "author": "admin"
                    },
                    {
                        "rating": "This definition is not rated yet.",
                        "defintion": "Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea, tempore labore veritatis maxime beatae est incidunt consectetur adipisci dolore reiciendis. Nostrum fugiat cumque beatae voluptatum.",
                        "def_id": "45",
                        "example": null,
                        "author": "admin"
                    },
                    {
                        "rating": "This definition is not rated yet.",
                        "defintion": "this sub def will rep abacus' \"venture capitalist\"",
                        "def_id": "31",
                        "example": null,
                        "author": "admin"
                    }
                ],
                "is_favourite": "Yes"
            }
        ]
    }
]

如果您仍然有错误,或者您正在寻找其他内容,请告知我们。

祝你好运,布拉德

答案 1 :(得分:0)

好吧,我找到了答案并学到了新东西。有错误时不要惊慌:)。我刚刚添加了一些额外的tpl。 感谢那些试图帮助我的人。抱歉,麻烦。

Ext.define('Sencha.view.Contacts', {
extend: 'Ext.List',
xtype: 'contacts',

config: {
    title: 'Stores',
    cls: 'x-contacts',

    store: 'Contacts',
    itemTpl: [

        '<div>',
            '<h2><b>Hello</b></h2>',
            '<tpl for="data">',
                '<div> Status - {status}</div>',
                '<div> Author - {author}</div>',
                '<div> Word - {name}</div>',
                '<div> Category - {category}</div>',
                '<tpl for="definitions">',
                   '<div style="margin-left:100px;"> rating - {rating} </div>',
                    '<div style="margin-left:100px;">Definition: {defintion} </div>',
                     '<div style="margin-left:100px;">Author: {author} </div>',
               '</tpl>',
            '</tpl>',
        '</div>'
    ].join('')
}
});