商店更新后如何调整 Sencha Touch 选择字段选择器的大小?

发布于 2024-10-30 09:47:25 字数 1082 浏览 2 评论 0原文

我正在开发 Sencha Touch 应用程序。我目前正在尝试获取由商店填充的 SelectField。

我的商店的代码是:

var store_Blocks = new Ext.data.JsonStore({
    model: 'Blocks',
    proxy: {
        type: 'ajax',
        url: '/search-blocks',
    },
    autoLoad: false,
    remoteFilter: true,
    listeners: {
        load: function(store, records, success) {
            Ext.getCmp('selectfield_Blocks').setDisabled(false);
        }
    }
});

我的选择字段的代码是:

{
    id: 'selectfield_Blocks',
    xtype: 'selectfield',
    name: 'block',
    label: 'Block number',
    disabled: true,
    store: store_Blocks,
    listeners: {
        change: function(selectfield, block) {
            ...
        }
    }
}

该选择字段位于浮动面板内。每次我 show() 浮动面板时,我的商店都会自行更新。因此,选择字段也会更新。但是,这仅在我第一次 show() 面板时有效。随后我 show() 浮动面板时,选择字段正确显示更新的数据,但是当我单击选择字段时显示的选择器未正确调整大小。它的大小根据浮动面板首次显示时有多少行数据而定。

TLDR:商店更新后如何调整 Sencha Touch 选择字段选择器的大小?

下面是屏幕截图。第二次单击选择字段时,选择器面板不会调整大小以适应整个商店的内容。

在此处输入图像描述

I'm developing a Sencha Touch application. I'm currently trying to get a SelectField to be populated by store.

The code for my store is:

var store_Blocks = new Ext.data.JsonStore({
    model: 'Blocks',
    proxy: {
        type: 'ajax',
        url: '/search-blocks',
    },
    autoLoad: false,
    remoteFilter: true,
    listeners: {
        load: function(store, records, success) {
            Ext.getCmp('selectfield_Blocks').setDisabled(false);
        }
    }
});

The code for my select field is:

{
    id: 'selectfield_Blocks',
    xtype: 'selectfield',
    name: 'block',
    label: 'Block number',
    disabled: true,
    store: store_Blocks,
    listeners: {
        change: function(selectfield, block) {
            ...
        }
    }
}

This select field is inside a floating panel. Every time I show() the floating panel, my store updates itself. As such, the select field also becomes updated. However, this works only the first time when I show() the panel. The subsequent times I show() the floating panel, the selectfield correctly shows the updated data, but the picker that shows up when I click the selectfield is not correctly resized. It is sized according to how many rows of data there was when the floating panel was first shown.

TLDR: How to resize a Sencha Touch selectfield's picker after the store has been updated?

Below is a screenshot. The second time I click the selectfield, the picker panel does not resize to fit the content of the whole store.

enter image description here

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

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

发布评论

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

评论(2

摘星┃星的人 2024-11-06 09:47:25

看来设置宽度和高度部分解决了问题。

Ext.getCmp('selectfield_Blocks').getListPanel().setHeight(300);
Ext.getCmp('selectfield_Blocks').getListPanel().setWidth(100);

我仍然遇到一些其他问题,有时无法从选择字段中选择项目。很奇怪。

It seems like setting the width and height fixed the problem partly.

Ext.getCmp('selectfield_Blocks').getListPanel().setHeight(300);
Ext.getCmp('selectfield_Blocks').getListPanel().setWidth(100);

I'm still having some other problems where I'm unable to sometimes select an item from the selectfield. Quite weird.

余生再见 2024-11-06 09:47:25

感谢您的解决方法,我做了一些不同的事情

    selectField.setOptions(options);
    if (Ext.isDefined(selectField.listPanel)) {
        selectField.listPanel.destroy();
        selectField.listPanel = undefined;
    }

,它可能效率较低,但每次数据更改时它都会自行计算宽度和高度。

Thanks to your workaround I did something a bit different

    selectField.setOptions(options);
    if (Ext.isDefined(selectField.listPanel)) {
        selectField.listPanel.destroy();
        selectField.listPanel = undefined;
    }

It might be a bit less efficient, but it calculates the width and height by itself every time the data is changed.

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