Sencha Touch2:解析嵌套的Json数据 [英] Sencha Touch2: Parsing nested Json data

查看:116
本文介绍了Sencha Touch2:解析嵌套的Json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是Sencha Touch2的新手,在解析嵌套的Json数据并显示在列表中时遇到了问题. 这是我的Json样子:

Hi am new to Sencha Touch2, facing problem while parsing nested Json data and showing in list. Here is my Json looks like:

[{"task":
{"agent":{"activeFlag":"false",
    "shiftId":"0","id":"0","deleteFlag":"false"},
      "id":"124","status":"Unassigned",
    "assignment":{"pnr":
    {"locator":"ABCDEF","connectTime":"0","id":"0"},
        "id":"123",
        "alerts":"Delay"
        "customers":[
            {"frequentNumber":"12345",
                "doNotMissFlag":"false",
                "customerScore":"0",
                "lastName":"XYZ",
                "firstName":"ABC",
                "primaryFlag":"true",
                "customerId":"56789"},
             {"frequentNumber":"987654",
                 "doNotMissFlag":"false",
                 "customerScore":"0",
                 "lastName":"PQR",
                "firstName":"STU ",
                 "cartNumber":"0",
                 "primaryFlag":"false",
                 "customerId":"54321"}]},
  }},
    {"task":{"agent":{......

可以获取代理"值,分配"值,但不能获取客户"值. 这是模型. ModelList.js:

am able to get 'agent' values, 'assignment' values but not able to get 'customers'. here are models. ModelList.js:

Ext.define('CustomList.model.ModelList', {
    extend: 'Ext.data.Model',
    xtype:'modelList',
    requires:['CustomList.model.Customers'],
    config: {
            fields:['task'],
        proxy:{
            type:'ajax',
            url:'http://localhost:9091/CustomListJson/app/store/sample.json',
            reader:{
            type:'json'

        }
    },
    hasMany:{model:'CustomList.model.Customers',
             name:'customers'}
    }

});

Customers.js:

Customers.js:

Ext.define('CustomList.model.Customers', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
            'firstName','lastName'
        ],
        belongsTo: "CustomList.model.ModelList"
    }

});

这是我的ShowList.js:

Here is my ShowList.js:

Ext.define('CustomList.view.ShowList',{
    extend:'Ext.Panel',
    xtype:'showList',
    config:{
        layout:'fit',
        styleHtmlContent:'true',
        styleHtmlCls:'showListCls',
        items:[
            {
                xtype:'list',
                id: 'listitems',
                store:'StoreList',
                itemTpl:['{task.assignment.alerts}', '<div>',
                    '<h2><b>FirstName: </b></h2>',
                    '<tpl for="Customers">',      // could not able to get and show in list
                    '<div> - {firstName}</div>',  // could not able to get and show in list
                    '</tpl>',
                    '</div>']
 // am able get the below values in list
//                itemTpl:'{task.assignment.alerts}'
//                itemTpl:'{task.assignment.pnr.locator}'
//                  itemTpl:'{task.agent.activeFlag}'
//                itemTpl: '<b>{firstName} {lastName}     </b><br>'+'pnr: '+ '{locator}  <br>' +
//                    'Alerts: <font color="#990000">'+'{alerts} </font>' +'status: '+'{status} '
               }]


    }
});

这是我的StoreList.js:

Here is my StoreList.js:

Ext.define('CustomList.store.StoreList', {
    extend:'Ext.data.Store',
    requires:['Ext.data.reader.Json'],
    config:{
        model:'CustomList.model.ModelList',
        autoLoad:'true'

    }
});

我已遵循以下规则: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.reader.Reader 但无法显示在列表中.谁能帮帮我吗.谢谢.

I have followed this :http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.reader.Reader but could not able show in list. Can any one Please help me. Thanks.

推荐答案

我为我的问题找到了解决方案. 我在ShowList.js中进行了更改: 使用了这个:

I got the solution for my question. I made changes in ShowList.js: used this:

   itemTpl:['{task.assignment.alerts} <div>',
                    '<tpl for="task.assignment.customers">',
                    'firstName: {firstName}<br>',
                    '</tpl> </div>'
                ].join('')

使用上面的我可以显示客户"的项目.谢谢.

using the above i can show items of 'customers'. Thanks.

这篇关于Sencha Touch2:解析嵌套的Json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆