在 ext 4 中从控制器中选择网格的第一条记录

发布于 2024-12-31 21:09:06 字数 1238 浏览 1 评论 0原文

我正在尝试选择网格的第一行。然而,以下给了我

“视图未定义”

  onLaunch: function () {
        var partsStore = this.getPartsStore();
        partsStore.load({
            callback: this.onPartsLoad,
            scope: this
        });
    },
    onPartsLoad: function (selection) {

        var grid = Ext.getCmp('partsViewGrid');
        grid.getSelectionModel().select(0);
        var form = Ext.getCmp('partForm');
        form.loadRecord(selection[0]);
    },

我的观点

Ext.define('Pandora.view.PartsList', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.partslist',
    store: 'Parts',
    initComponent: function () {
        this.id = "partsViewGrid";
        this.height = 400;
        this.xtype = 'gridpanel';
        this.border = 0;
        this.columns = [
            {
                xtype: 'gridcolumn',
                id: 'description',
                dataIndex: 'Name',
                text: 'Descriptfion'
            },
            {
                xtype: 'gridcolumn',
                id: 'done',
                dataIndex: 'Completed',
                text: 'Done',
                renderer: renderProduct
            }
        ];

        this.callParent();
    }
});

I'm trying to select the first row of my grid. However the following gives me

"views is undefined"

  onLaunch: function () {
        var partsStore = this.getPartsStore();
        partsStore.load({
            callback: this.onPartsLoad,
            scope: this
        });
    },
    onPartsLoad: function (selection) {

        var grid = Ext.getCmp('partsViewGrid');
        grid.getSelectionModel().select(0);
        var form = Ext.getCmp('partForm');
        form.loadRecord(selection[0]);
    },

My view

Ext.define('Pandora.view.PartsList', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.partslist',
    store: 'Parts',
    initComponent: function () {
        this.id = "partsViewGrid";
        this.height = 400;
        this.xtype = 'gridpanel';
        this.border = 0;
        this.columns = [
            {
                xtype: 'gridcolumn',
                id: 'description',
                dataIndex: 'Name',
                text: 'Descriptfion'
            },
            {
                xtype: 'gridcolumn',
                id: 'done',
                dataIndex: 'Completed',
                text: 'Done',
                renderer: renderProduct
            }
        ];

        this.callParent();
    }
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陈甜 2025-01-07 21:09:06

如果您只想要一条记录,则不需要其中的数组“selection[0]”。在 ExtJs 4.x 中,这对我来说总是有效:

grid.getSelectionModel().select(0)

If you just want one record you don't need the array "selection[0]" in there. In ExtJs 4.x this always works for me:

grid.getSelectionModel().select(0)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文