Ext:Ext.menu.Menu动态加载菜单

var createMenu = new Ext.menu.Menu({
    id : 'mainMenu',
    items : [],
    listeners : {
     click : function(menu, item, e) {
      var record = groupLevelStore.getAt(item.getId());
      addGroup(record);
     }
    }
   })
 // 字段
 var groupLevelFields = ["id", "levelName", "capacity"];
 // 记录
 var groupLevelRecord = new Ext.data.Record.create([{
    name : "id"
   }, {
    name : "levelName"
   }, {
    name : "capacity"
   }]);
 // 数据
 groupLevelStore = new Ext.data.Store({
  // 代理
  proxy : new Ext.data.HttpProxy({
     url : Action.corp.GroupLevelMngAction.GET_USERDEFAULTGROUPLEVEL,
     method : "POST"
    }),
  // 解析器
  reader : new Ext.data.JsonReader({
     fields : groupLevelFields,
     root : "data",
     id : "id",
     totalProperty : "totalCount"
    }, groupLevelRecord)
 });
 groupLevelStore.load({
    callback : function(records, options, success) {
     
     if (records.length == 0) {
      Ext.getCmp('createGroup').setDisabled(true);
     }else{
      for (var i = 0; i < records.length; i++) {
       var item = new Ext.menu.Item({
          text : "创建" + records[i].data.levelName,
          id : i + ''
         });
       createMenu.addItem(item);
      }
     }
    },
    scope : groupLevelStore
   })
 // 工具栏
 var toolBar = new Ext.Toolbar(["", "-", "", {
    text : "创建群",
    id:"createGroup",
    iconCls : "addicon",
    menu : createMenu
   }, 
   }]);

阅读更多

没有更多推荐了,返回首页