1

ExtJSアプリケーションでは、EditorGridPanelを使用してサーバーからのデータを表示します。

var applicationsGrid = new Ext.grid.EditorGridPanel({
    region: 'west',
    layout: 'fit',
    title: '<img src="../../Content/img/app.png" />  Приложения',
    collapsible: true,
    margins: '0 0 5 5',
    split: true,
    width: '30%',
    listeners: { 'viewready': { fn: function() { applicationsGridStatusBar.setText('Приложений: ' + applicationsStore.getTotalCount()); } } },
    store: applicationsStore,
    loadMask: { msg: 'Загрузка...' },
    sm: new Ext.grid.RowSelectionModel({
        singleSelect: true,
        listeners: { 'rowselect': { fn: applicationsGrid_onRowSelect} }
    }),
    viewConfig: { forceFit: true },
    tbar: [{
        icon: '../../Content/img/add.gif',
        text: 'Добавить'
    }, '-', {
        icon: '../../Content/img/delete.gif',
        text: 'Удалить'
    }, '-'],
    bbar: applicationsGridStatusBar,
    columns: [{
        header: 'Приложения',
        dataIndex: 'ApplicationName',
        tooltip: 'Наименование приложения',
        sortable: true,
        editor: {
            xtype: 'textfield',
            allowBlank: false
        }
    }, {
        header: '<img src="../../Content/img/user.png" />',
        dataIndex: 'UsersCount',
        align: 'center',
        fixed: true,
        width: 50,
        tooltip: 'Количество пользователей приложения',
        sortable: true
    }, {
        header: '<img src="../../Content/img/role.gif" />',
        dataIndex: 'RolesCount',
        align: 'center',
        fixed: true,
        width: 50,
        tooltip: 'Количество ролей приложения',
        sortable: true}]
    });

リーダーなしでJsonStoreを使用すると機能しますが、フィールドを更新しようとすると、「update」ではなく「create」URLが使用されます。

var applicationsStore = new Ext.data.JsonStore({
    root: 'applications',
    totalProperty: 'total',
    idProperty: 'ApplicationId',
    messageProperty: 'message',
    fields: [{ name: 'ApplicationId' }, { name: 'ApplicationName', allowBlank: false }, { name: 'UsersCount', allowBlank: false }, { name: 'RolesCount', allowBlank: false}],
    id: 'app1234',
    proxy: new Ext.data.HttpProxy({
        api: {
            create: '/api/applications/getapplicationslist1',
            read: '/api/applications/getapplicationslist',
            update: '/api/applications/getapplicationslist2',
            destroy: '/api/applications/getapplicationslist3'
        }
    }),        
    autoSave: true,
    autoLoad: true,
    writer: new Ext.data.JsonWriter({
        encode: false,
        listful: false,
        writeAllFields: false
    })
});

問題は、リーダーを使用していないことだと思いますが、JsonReaderを使用すると、グリッドにデータがまったく表示されなくなります。

var applicationReader = new Ext.data.JsonReader({
    root: 'applications',
    totalProperty: 'total',
    idProperty: 'ApplicationId',
    messageProperty: 'message',
    fields: [{ name: 'ApplicationId' }, { name: 'ApplicationName', allowBlank: false }, { name: 'UsersCount', allowBlank: false }, { name: 'RolesCount', allowBlank: false}]
});

var applicationsStore = new Ext.data.JsonStore({
    id: 'app1234',
    proxy: new Ext.data.HttpProxy({
        api: {
            create: '/api/applications/getapplicationslist1',
            read: '/api/applications/getapplicationslist',
            update: '/api/applications/getapplicationslist2',
            destroy: '/api/applications/getapplicationslist3'
        }
    }),
    reader: applicationReader,
    autoSave: true,
    autoLoad: true,
    writer: new Ext.data.JsonWriter({
        encode: false,
        listful: false,
        writeAllFields: false
    })
});

だから、誰もが問題が何であるか、そしてそれを解決する方法を知っていますか?サーバーから返されたデータはJson形式であり、継ぎ目は問題ありません

{"message":"test","total":2,"applications":[{"ApplicationId":"f82dc920-17e7-45b5-98ab-03416fdf52b2","ApplicationName":"Archivist","UsersCount":6,"RolesCount":3},{"ApplicationId":"054e2e78-e15f-4609-a9b2-81c04aa570c8","ApplicationName":"Test","UsersCount":1,"RolesCount":0}]}
4

5 に答える 5

5

同じ問題が発生しました。jsonストアでSuccessプロパティを確立し、createメソッドからの応答でsuccesstrueを返すことで解決しました。これが私のコードです。それが役に立てば幸い

var EStore = new Ext.data.JsonStore
                ({
                   api: { read: 'getAssignedJobs',
                        create: 'createAssignedJobs',
                        update: 'updateAssignedJobs',
                        destroy: 'destroyAssignedJobs'},
                    root: 'jobData',
                    idProperty: 'Id',
                    autoSave: false,
                    autoLoad: true,
                    batch: true,
                    successProperty: 'success',
                    writer: new Ext.data.JsonWriter({ encode: true, writeAllFields: true }),
                    fields: [
                        { name: 'Id', type: 'int', mapping: 'Id' },
                        { name: 'ResourceId', type: 'int', mapping: 'fitter_id' },
                        { name: 'StartDate', type: 'date', dateFormat: "Y-m-d\\TH:i:s" },
                        { name: 'EndDate', type: 'date', dateFormat: "Y-m-d\\TH:i:s" },
                        { name: 'status', type: 'int' },
                        { name: 'job_id', type: 'int' }
                                ]
                });

これはサーバー側からの私のCreateメソッドです。

public JsonResult createAssignedJobs(string jobData)
    {
        var Jsondata = (JobfitterToScheduler)new JavaScriptSerializer().Deserialize<JobfitterToScheduler>(jobData);
        JobToFitterRepo jobtofitter = new JobToFitterRepo();
        if (Jsondata != null)
        {
            jobtofitter.insertJobToFitter(13, Jsondata.fitter_id, 0, DateTime.Now, DateTime.Now);
            return this.Json(new { success = true, jobData = Jsondata });
        }
        return null;
    }
于 2011-08-03T09:28:39.860 に答える
1

Ext.data.Apiのソースを見ると、動詞が台無しになっていると言えます。

restActions : { create : 'POST', read : 'GET', update : 'PUT', destroy : 'DELETE' },

私にとって、作成はPUTであり、更新はPOSTである必要があります。しかし、煎茶の人たちは別の考えを持っていると思います。ところで、ソースはExt3.3.1から取得されます

期待どおりに機能するようにrestActionsオブジェクトをオーバーライドできると思います。

Ext.data.Api.restActions = {
create  : 'PUT',
read    : 'GET',
update  : 'POST',
destroy : 'DELETE' };
于 2010-12-14T19:08:31.077 に答える
0

JsonStoreは、POSTとPUTのどちらを実行するかについてレコードIDをキーオフしていると思います。したがって、IDがユーザー生成ではない場合は、POSTを発行し、それ以外の場合はPUTを発行します。record.data.idではなくrecord.idを参照しています。

于 2010-06-09T12:15:45.383 に答える
0

私は何とかストア'id'設定オプションがdepricatedであることを知ることができました。

于 2010-06-09T11:57:02.470 に答える
0

最初の部分についてはわかりませんが(私のストアは同様のコードで正しい呼び出しを行います)、質問の2番目の部分に光を当てることができます。

Ext.data.JsonStoreはリーダーオブジェクトを受け入れませ-ソースからわかるように、フィールドのみを取り、常に独自のリーダーを作成します

Ext.data.JsonStore = Ext.extend(Ext.data.Store, {
    constructor: function(config){
        Ext.data.JsonStore.superclass.constructor.call(this, Ext.apply(config, {
            reader: new Ext.data.JsonReader(config)
        }));
    }
});

Ext2.xでは「ドキュメントどおり」であることが確認されています

http://www.sencha.com/forum/showthread.php?57189-2.x-Closed-Bug-in-Ext.data.JsonStore-cconstructor

したがって、独自のリーダーを提供する場合は、この場合、代わりにExt.data.Storeを作成する必要があります(これも私を捕らえました)

于 2011-02-02T10:01:15.687 に答える