2013-07-31 69 views
-1

而不是「Item 1」等,我想把我自己的數據放入extjs的可滾動菜單下拉列表中,然後發送值以查詢相應的頁面。這裏的ExtJS的菜單上的文檔:什麼是最好的方式把js數組放入extjs滾動菜單

var scrollMenu = new Ext.menu.Menu(); 
    for (var i = 0; i < 50; ++i){ // replace this loop with one that loops thru my data 
     scrollMenu.add({ 
      text: 'Item ' + (i + 1), // replace this with text from array (see my data below) 
      id: // replace this with number from array (see my data below) 
     }); 
    } 
    // scrollable menu 
    tb.add({ 
     icon: 'preview.png', 
     cls: 'x-btn-text-icon', 
     text: 'Scrolling Menu', 
     menu: scrollMenu 
    }); 

View an online sample並單擊菜單中的「滾動菜單」按鈕。

這是我的數據:

var locations = [ 
    [23, 'Main Room'], 
    [1, 'Main Lobby'], 
    [2, 'Training Room'], 
    [56, 'Main Office'], 
    [57, 'Lower Office'], 
    [9, 'Lower Lobby'], 
    [62, 'Conference Room'], 
    [22, 'Outdoor Patio'], 
    [63, 'Upper Lobby'] 
    ]; 

回答

0

這就是結束了工作!

var scrollMenu = new Ext.menu.Menu(); 
    Ext.each(locations, function (name, index, locationsItSelf) { 

     scrollMenu.add({ 
      // text: 'Item ' + (i + 1) 
      value: name[0], 
      text: name[1] 
     }); 
    }); 
0

這幾乎是相同的過程。循環它以將其轉換爲對象數組。

var items = []; 

Ext.Array.forEach(locations, function(item) { 
    items.push({ 
     id: 'item' + item[0], 
     text: item[1] 
    }); 
}); 

new Ext.menu.Menu({ 
    items: items 
}); 
+0

我對這個建議沒有任何運氣。我在項目[0]後面添加了一個逗號,並在新的Ext.menu.Menu前添加了「var scrollMenu =」({ – sloga

相關問題