dqxz96998 2014-07-31 12:31
浏览 31

如何从ExtJS 4.2.2中的其他控制器访问存储

I'm developing an application which is build in ExtJS 4.2.2 with symfony2 backend. Now I have following problem : Lets say that I have 2 mvc's in my frontend - One for managing users and other for managing their data.

Now when user want to delete row of data I have to set his name in that deleted record so it can be archived and other users would know who made the deletion.

The question is how can I access to currently logged in user data from my DataController.

I've tried this:

This is part of code in my DataController, it's responsible for archiving deleted record

//sel[0] is selected record
//console.log({{ app.user.username }}); //I tought it could work somehow :) but it did not
  sel[0].set('deleted_at', new Date()); //setting date of deletion
//get user store
//var usrStore = Ext.getStore('common_user.user_store'); 
  var usrStore = Ext.data.StoreManager.lookup('common_user.user_store') 
  console.log(usrStore); //in both cases ruterns undefined
//sel[0].set('deleted_by', );  //here i want to save user name in column named "deleted_by"
  sel[0].save();
  sel[0].commit();

  grid.getStore().sync();
  grid.getStore().reload(); //reload grid

  grid.getStore().remove(sel[0]); //remove from grid

This is how I've configured User store proxy

proxy: {
        type: 'rest',
        url: Routing.generate('webit_sencha_get',{store: 'common_user.user_store'}),
        appendId: false,
        batchActions: true,
        reader: {
            type: 'json',
            root: 'data'
        },
        writer: {
            type: 'json',
            root: 'data',
            encode: true,
            writeAllFields: true
        }
    }

Maybe I should load User grid on init of my data controller ? But still, I don't know how to.

Ext.define('Data.controller', {
    extend: Ext.app.Controller,
    init: function() {
        this.control({
            ...
            'data_grid': {
                afterrender: this.onDataGridRender
            },
            'archive_grid': {
                afterrender: this.onDataArchiveGridRender
            },
            'common_user_grid': {
                afterrender: this.onUserGridRender // ????
            }
        });
    },
    ...

So the question is how can I access (if it's possible) name of currently logged in user from other controller

I'll be thankfull for any guidance.

Problem fixed, I just had to pass parameter to my backend save option and then get current user there

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 Revit2020下载问题
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大