当前位置: 代码迷 >> JavaScript >> ExtJS 四 : desktop shortcut location
  详细解决方案

ExtJS 四 : desktop shortcut location

热度:717   发布时间:2012-09-03 09:48:39.0
ExtJS 4 : desktop shortcut location
  ExtJS 4 Desktop 例子中的桌面图标始终在第一列显示,不论有多少个。重写Desktop的部分方法,让其自动适应位置。

  Ext.override(Ext.ux.desktop.Desktop, {
      createDataView: function () {
        var me = this;
        return {
          xtype: 'dataview',
          overItemCls: 'x-view-over',
          trackOver: true,
          itemSelector: me.shortcutItemSelector,
          store: me.shortcuts,
          tpl: new Ext.XTemplate(me.shortcutTpl),
          listeners: {
            'refresh': me.positionItems,
            'resize': me.positionItems
          }
        };
      },

      positionItems: function() {
        var me = this,
            height = this.getHeight(),
            x = 0,
            y = 0;

        // get  the max width and height of shortcuts
        if (!me.itemWidth && !me.itemHeight) {
          me.itemHeight = 0;
          var h = 0, rh;

          this.all.each(function(item) {
            var el = Ext.get(item),
                box = el.getBox();
            me.itemWidth = me.itemWidth || box.right;
            me.itemHeight = (rh = box.bottom - h) > me.itemHeight ? rh : me.itemHeight;
            h = box.bottom;
          });
        }

        this.all.each(function(item) {
          var el = Ext.get(item);
          if ((y+me.itemHeight) > height) {
            x += me.itemWidth;
            y = 0;
          }
          el.setXY([x, y]);
          y += me.itemHeight;
        });
      }
    });
  相关解决方案