木叶下521 2013-11-01 15:39
浏览 366
已采纳

json嵌套,怎样取出数据显示在grid中

json数据:{"counts":1,"surveys":[{"count":0,"createTime":null,"deadline":null,"des":null,"grade":false,"id":1,"name":"关于JSP科恒调查","open":false,"password":null,"publishTime":null,"surveyType":{"id":1,"name":"教学反馈调查类"}}]}
数据我就不贴那么多啦
model:[code="java"]Ext.define('MyExtJS.model.MenuModel', {
extend : 'Ext.data.Model',
fields : [{
name : 'id',
mapping : 'id'
}
, 'name', 'isOpen', 'count',
{
name : 'type',
mapping : 'surveyType.name'
},{
name : 'createTime',
mapping : 'createTime',
type : 'date',
dateFormat : 'timestamp'
}, {
name : 'publishTime',
mapping : 'publishTime',
type : 'date',
dateFormat : 'timestamp'
}, 'password', 'isGrade']
});[/code]
store:[code="java"]Ext.define('MyExtJS.store.SurveyStore', {
extend : 'Ext.data.Store',
model : 'MyExtJS.model.SurveyModel',

        autoLoad : true,

        proxy : {
            type : 'ajax',
            url:'menu/survey!quryAllSurvey',
                            reader : {
                                root : 'surveys',
                                type: 'json',  
                                totalProperty : 'counts'
                            },
                            // sends single sort as multi parameter
                            simpleSortMode : true
                        },
                        sorters : [{
                                    property : 'id',
                                    direction : 'ASC'
                                }]


    })

[/code]
view:[code="java"]Ext.define('MyExtJS.view.SurveyList', {
extend : 'Ext.grid.Panel',
alias : 'widget.surveylist',

        title : '问卷列表',
        store : 'SurveyStore',
        selType : 'cellmodel', // 设置为单元格选择模式Ext.selection.CellModel
        tbar : [{
                    text : '取得所选单元格',
                    handler : function() {
                        var cell = grid.getSelectionModel()
                                .getCurrentPosition();
                        alert(Ext.JSON.encode(cell));
                    }
                }],
        initComponent : function() {
            this.columns = [{
                        id : 'surveys',
                        text : "id",
                        dataIndex : 'id', // 与Model对应
                        // flex : 1,
                        // renderer: renderTopic,
                        sortable : false
                    }, {
                        text : "名称",
                        dataIndex : 'name',
                        flex : 1,
                        // hidden: true,
                        sortable : true
                    }, {
                        text : "是否开放",
                        dataIndex : 'isOpen',
                        xtype : 'booleancolumn',
                        trueText : '是',
                        falseText : '否',
                        // width: 70,
                        // align: 'right',
                        sortable : true
                    }, {
                        // id: 'last',
                        text : "问卷类型",
                        dataIndex : 'type',
                        // width: 150,
                        // renderer: renderLast,
                        sortable : true
                    }, {
                        text : "问卷限制数量",
                        dataIndex : 'count',
                        // width: 70,
                        // align: 'right',
                        sortable : true
                    }, {
                        text : "创建时间",
                        dataIndex : 'createTime',
                        xtype : 'datecolumn',
                        format : 'Y-m-d h:m:s',
                        // width: 70,
                        // align: 'right',
                        sortable : true
                    }, {
                        text : "发布时间",
                        dataIndex : 'publishTime',
                        xtype : 'datecolumn',
                        format : 'Y-m-d h:m:s',
                        // width: 70,
                        // align: 'right',
                        sortable : true
                    }, {
                        text : "密码",
                        dataIndex : 'password',
                        // width: 70,
                        // align: 'right',
                        sortable : true
                    }, {
                        text : "是否是打分问卷",
                        dataIndex : 'isGrade',
                        xtype : 'booleancolumn',
                        trueText : '是',
                        falseText : '否',
                        // width: 70,
                        // align: 'right',
                        sortable : true
                    }];
            this.callParent(arguments);
        }
    });[/code]
  • 写回答

1条回答 默认 最新

  • u012524790 2013-11-01 16:56
    关注

    就用对象名.属性名就好了·

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题