extjs嵌套数据网格过滤器和重新加载不在viewModel上工作

时间:2016-07-05 01:25:46

标签: extjs model store extjs-grid

为什么不使用过滤器和重新加载商店网格... 数据嵌套.. 我希望父母使用代理模型..

嵌套数据json

服务器sssssssss s s s s

{
    "success": true,
    "data": {
        "taksitler": [
         {
            "taksit_id": "13",
            "mebla": "100.00",
            "tarih": "2016-10-31",
            "odeme": "1"
         },
         {
            "taksit_id": "14",
            "mebla": "150.00",
            "tarih": "2016-10-31",
            "odeme": "0"
         },
         {
            "taksit_id": "15",
            "mebla": "16.00",
            "tarih": "2016-10-31",
            "odeme": "0"
         },
         {
            "taksit_id": "16",
            "mebla": "14.00",
            "tarih": "2016-10-31",
            "odeme": "0"
         },
         {
            "taksit_id": "17",
            "mebla": "20.00",
            "tarih": "2016-10-31",
            "odeme": "0"
        }
        ]
   }
}

model.plan.Plan

Ext.define('Rent.model.plan.Plan', {
    extend: 'Ext.data.Model',

    proxy: {
        type: 'ajax',
        idParam: 'plan_id',

        api: {
            create: 'bayi/plan/create',
            read: 'bayi/plan/read',
            update: 'bayi/plan/update',
            destroy: 'bayi/plan/destroy',
        },

        reader:{
            type:'json',
            rootProperty: 'data'
        },

        writer: {
            encode: true,
            writeAllFields: true,
            rootProperty: 'data',
            allDataOptions: {
                associated: true
            }
        },

    },

    fields: [
        {name: 'plan_id', type: 'int'},
        {name: 'fatura_id', type: 'int'},
        {name: 'hesap_id', type: 'int'},
    ],

    hasMany: {
        model: 'Rent.model.plan.Taksitler',
        name:'taksitler', 
        associationKey:'taksitler'
    }

});

model.plan.Taksitler

Ext.define('Rent.model.plan.Taksitler',{
    extend: 'Ext.data.Model',

    fields: [
        {name: 'taksit_id', type: 'int'},
        {name: 'mebla', type: 'number'},
        {name: 'tarih', type: 'date', dateWriteFormat: 'Y-m-d'},
        {name: 'odeme', type: 'boolean', defaultValue: false}
    ],

});

store.plan.taksitler

Ext.define('Rent.store.plan.Taksitler', {
    extend: 'Ext.data.Store',

    alias: 'store.taksitler',
    model : 'Rent.model.plan.Taksitler',

    pageSize: 0,

});

store.plan.Plan

Ext.define('Rent.store.plan.Plan', {
    extend: 'Ext.data.Store',

    alias: 'store.plan',
    model : 'Rent.model.plan.Plan',

    pageSize: 0,

});

网格

Ext.define('Rent.view.odemeplani.OdemePlani', {
    extend: 'Ext.window.Window',
    defaultListenerScope: true,

    viewModel: true,

    items: [{
        xtype: 'gridpanel',

        bind: {
            store: '{plan.taksitler}'
        },

        columns: [
            {
                text: 'ID',
                dataIndex: 'taksit_id',
                hidden: true
            },
            {
                xtype: 'numbercolumn',
                text: 'Mebla',
                dataIndex: 'mebla',
                format: '0.00',
                flex: 4,
                resizable: false,
                sortable: false,
            },
            {
                xtype: 'datecolumn',
                text: 'Tarih',
                dataIndex: 'tarih',
                format: 'd.m.Y',
                flex: 4,
                resizable: false,
            },
            {
                xtype: 'booleancolumn',
                text: 'Ödeme',
                dataIndex: 'odeme',
                trueText: 'Yapıldı',
                falseText: 'Yapılmadı'
            }
        ],  
    }],

    tbar: [
        {
            text: 'Yenile',
            iconCls: 'icon-yenile-16',
            handler: 'yenile'
        },
    ],

    // events

    yenile: function(){
        this.down('grid').store.reload(); 
        // fail : 
        // GET http://localhost/Rent.model.plan.Taksitler?_dc=1467681109503 
        // 404 (Not Found) ???? Why doesn't parent's proxy
    },

    // ~ events

    constructor: function(config) {
        this.callParent(arguments);

        this.getViewModel().linkTo('plan', {
            type: 'Rent.model.plan.Plan',
            id: config.id
        });

    },


});

1 个答案:

答案 0 :(得分:0)

你应该把数组直接放在数据中,因为你把它声明为root,所以json应该是这样的:

JSON:

{
"success": true,
"data": [{
    "taksit_id": "13",
    "mebla": "100.00",
    "tarih": "2016-10-31",
    "odeme": "1"
}, {
    "taksit_id": "14",
    "mebla": "150.00",
    "tarih": "2016-10-31",
    "odeme": "0"
}, {
    "taksit_id": "15",
    "mebla": "16.00",
    "tarih": "2016-10-31",
    "odeme": "0"
}, {
    "taksit_id": "16",
    "mebla": "14.00",
    "tarih": "2016-10-31",
    "odeme": "0"
}, {
    "taksit_id": "17",
    "mebla": "20.00",
    "tarih": "2016-10-31",
    "odeme": "0"
}]

}