ExtJs将商店更改为REST

时间:2016-04-27 12:35:47

标签: extjs

请你帮我休息一下。我希望我的商店成为REST,我看到了一些使用HttpProxy的样本,并试图做同样的事情,但它不起作用。

正如我在样本商店中注意到的那样,总是创建如下:var store = Ext.create ... 如果有问题,那么我不知道在哪里调用Ext.create,之前我总是在网格中使用storeId并且运行良好。

P.S。为什么没有只有空白字段的商店数据就无法创建网格?

这是我的'TestStore'代码:

Ext.define('MVC.store.Notes', {
extend  : 'Ext.data.Store',

requires : [
    'MVC.model.Note'
],

storeId : 'TestStore',
model   : 'MVC.model.Note',
autoLoad: true,
proxy: {
    type: 'rest',
    url: 'rest/notes',
    reader: {
        type: 'json',
        rootProperty: 'data'
    },
    writer: {
        type: 'json'
    }
}
});

和网格:

Ext.define('MVC.view.NotesGrid', {
extend: 'Ext.grid.Panel',
xtype: 'notesGrid',

title: 'Note-list',

//  store: 'Notes',
store: 'TestStore',
columns: [
    {
        text: 'Name',
        dataIndex: 'name',
        flex: 1
    },
    {
        text: 'Creation Date',
        xtype: 'datecolumn',
        format: 'd-m-Y',
        dataIndex: 'createDate',
        flex: 1
    },{
        text: 'Last Modified',
        xtype: 'datecolumn',
        format: 'd-m-Y',
        dataIndex: 'modifiedDate',
        flex:1
    }, {
        text: 'Text',
        dataIndex: 'noteText',
        flex: 3
    }
]
});

1 个答案:

答案 0 :(得分:1)

不回答主要问题,只回答你的问题:

  • 当您Ext.define()商店时,您可以定义该类。
  • 当您Ext.create()商店时,您可以定义实例。

班级不能保存任何数据,只有实例可以。

如果将商店的类名添加到主stores文件中应用程序定义中的Application.js数组,则告诉应用程序创建该类的一个全局存储实例。

从具有固定商店标识的商店类,您只能为每个应用程序创建一个实例;从没有固定storeId的商店类中,您可以创建多个实例(例如,每个网格一个)。

相关问题