1

我有一个由商店填充的列表项。商店加载后,列表似乎不会以适当的高度调整大小。高度实际上为零。你们有什么建议让列表在加载商店后重新计算它的高度?

我的观点:

            xtype: 'fieldset',
            cls: 'damage-list-fieldset',
            margin: '',
            itemId: 'damageFieldSet',
            flex: 1,
            layout: {
                type: 'fit'
            },
            items: [
                {
                    xtype: 'list',
                    action: 'showNotes',
                    cls: 'damage-list',
                    itemCls: 'x-list-item-label',
                    itemId: 'DamageList',
                    disableSelection: true,
                    height: 'auto',
                    emptyText: 'No damage has been reported',
                    itemTpl: [
                        '<table border="0" width="100%">',
                        '    <tr>',
                        '        <td class="part" width="30%">{part}</td>',
                        '        <td class="note" width="30%">{date}</td>',
                        '        <td class="type" width="30%">{type}</td>',
                        '        <td class="note" width="10%"><div class="count">{noteCount}</div></td>',
                        '    </tr>',
                        '</table>',
                        ''
                    ],
                    store: 'Damage',
                    grouped: true,
                    onItemDisclosure: false
                }
            ]
        },

我意识到 itemTpl 中不应该有表格,但现在让我们忽略它。

这是我目前强迫它工作的方式。我从控制器存储加载回调中推送高度。

        Ext.getStore('Damage').load({
        params: {repairOrderId: this.repairOrderId},
        callback: function(records, operation, success) {
            if(records.length) {
                report.getComponent('noteInstruction').setHidden(records.length == 0);

                /* Calculate the height of the damage rows and set it*/
                var location = new Array();
                var locationCount = 0;
                for(var i = 0; i < records.length; i++) {
                    if(location.indexOf(records[i].data.location) < 0) {
                        location.push(records[i].data.location);
                        locationCount++;
                    }
                }
                var damageRow = 54;
                var damageHeader = 56;
                var damageHeight = (records.length * damageRow) + (locationCount * damageHeader);
                report.getComponent('damageFieldSet').getComponent('DamageList').setHeight(damageHeight);
                report.getComponent('damageFieldSet').getComponent('DamageList').setScrollable(false);
            }
            Ext.Viewport.setMasked(false);
        },
        scope: this
    });

不是很优雅,因为我只是在设定的高度上卡住。

所以问题是,在从商店取回记录后,如何强制列表重新绘制其高度?

4

1 回答 1

1

加载过程是异步的,加载后的回调不一定会影响列表。

  • 高度可以从 list.element.html 中读取,您不需要计算高度,因为列表已经有一个列表。
  • 加载已经自动更新列表。
  • Sencha 2.2.1 的列表组件以不同的方式生成。它只生成可见项目的数量加 1 并切换列表项的位置
  • height:'auto' 最好用 flex: 1 代替

我建议你

  • 删除你的回调
  • 打电话给店家看看店里有没有货
  • 将列表项高度设置为固定值(不要尝试设置列表中每一行的高度,否则使用 dataview 并在 dataview upatedata 事件上设置高度)
  • 请记住,dataview 比 list 慢得多,并且在 list 上,所有项目都意味着具有相同的高度

最后但并非最不重要的一点是,您可以在列表配置中使用:

variableHeights: true
于 2013-08-01T10:44:18.640 回答