为什么添加newRecord []为空

时间:2017-08-07 09:38:11

标签: extjs extjs4 extjs4.1 extjs4.2

添加newRecord时出现问题,控制台始终输出[]

请帮帮我。

_storePR2.add(_key.data);
_storePR2.commitChanges();
var newRecord = _storePR2.getNewRecords();
console.log('newRecord',newRecord);

输出:newRecord []

enter image description here

这是我的商店代码和型号:

Ext.define('Sasmita.store.vending.purchase.Purchasegoodrec', {
    extend: 'Ext.data.Store',

    requires: [
        'Ext.data.proxy.Ajax',
        'Ext.data.reader.Json',
        'Ext.data.Field'
    ],

    constructor: function(cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            autoLoad: false,
            storeId: 'vending.purchase.Purchasegoodrec',
            proxy: {
                type: 'ajax',
                url: 'jsonresult/Sasmita_Vending_Purchase/getPurchaseGoodrec',
                reader: {
                    type: 'json',
                    root: 'data',
                    idProperty: 'sitecode2'
                }
            },
            fields: [
                {
                    name: 'purchase_id_tr'
                },
                {
                    name: 'parent_id'
                },
                {
                    name: 'file_ext'
                },
                {
                    name: 'file_name'
                },
                {
                    name: 'file_size'
                },
                {
                    name: 'description'
                },
                {
                    name: 'id'
                },
                {
                    name: 'id_file'
                },
                {
                    name: 'id_po'
                },
                {
                    name: 'qty_hasil'
                },
                {
                    name: 'no_pr'
                },
                {
                    dateFormat: 'Ymd',
                    name: 'date_pr',
                    type: 'date'
                },
                {
                    name: 'warehouse'
                },
                {
                    name: 'warehouse_name'
                },
                {
                    name: 'row_created_by'
                },
                {
                    name: 'row_created_datetime'
                },
                {
                    name: 'row_changed_by'
                },
                {
                    name: 'row_changed_datetime'
                },
                {
                    name: 'title'
                },
                {
                    name: 'notes'
                },
                {
                    name: 'qty_order'
                },
                {
                    name: 'no_po'
                },
                {
                    name: 'date_po'
                },
                {
                    name: 'supplier'
                },
                {
                    name: 'package'
                },
                {
                    name: 'qty_approve'
                },
                {
                    name: 'purchase_product_name'
                },
                {
                    name: 'unit'
                },
                {
                    name: 'unit_price'
                },
                {
                    name: 'total_price'
                },
                {
                    name: 'total_price_head'
                },
                {
                    name: 'vat'
                },
                {
                    name: 'net_price'
                },
                {
                    name: 'sum_total'
                }
            ]
        }, cfg)]);
    }
});

这个我的控制器操作按钮选择:

var me = this;
var _panel = me.getMainPanel();
var _tabpanel = _panel.down('#tabmaintain');
var _activetab = _tabpanel.getActiveTab();
var _window = button.up('window');
var _grid = _window.down('grid');
//var _girdd = this.getPanelSearch();
//var _grids = _girdd.down('grid');
var _gridSelected = _grid.getSelectionModel().getSelection();
//var row = _grid.store.indexOf(_gridSelected);
//console.log(row);
console.log(_gridSelected);
console.log(_grid);
//console.log(_girdd.down('grid'));
//selected=[];

//Check selected product
if(_gridSelected.length===0){
    Ext.Msg.alert('Warning','Please select product');
    return;
}

//Submit Product
var _gridPR = _activetab.down('#detailProduct');
var _storePR2 = _gridPR.getStore();
//console.log(_storePR2.data);
Ext.Array.each(_gridSelected,function(_key,_value,item){
    //console.log(selected.push(item));
    _validate = true;
    _storePR2.each(function(_storeData,_storeIndex){
        console.log(_key.data);
        if(_storeData.data.no_po === _key.data.no_po){
            _validate = false;
            Ext.Msg.alert('Warning','The Product had been picked');
            return;
        }
    });
    if(_validate){
        // Add record to the store by data
        _storePR2.add(_key.data);


        // Get array of new records from the store
        var newRecords = _storePR2.getNewRecords();
        console.log('newRecord',newRecords);

         // Commit changes after getting new records
        _storePR2.commitChanges();



        _window.close();
    }
});

2 个答案:

答案 0 :(得分:1)

这是因为您提交了更改,因此不再有任何新记录'。

在提交更改之前尝试获取新记录:

// Add record to the store by data
_storePR2.add(_key.data);

// Get array of new records from the store
var newRecords = _storePR2.getNewRecords();
console.log('newRecord',newRecords);

// Commit changes after getting new records
_storePR2.commitChanges();

这是fiddle

答案 1 :(得分:0)

首先,您需要添加记录来存储和提交更改,然后获取新记录。

 grid_store.add({'Name':"ab",'dob':"099"})
     grid_store.commitChanges();
     var newRecord = grid_store.getNewRecords()
     console.log('newRecord',newRecord);
 });

这是一个小提琴:http://jsfiddle.net/2p78md5t/3/