EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: mickypc on July 06, 2011, 07:26:04 AM



Title: Problem with menu appendItem
Post by: mickypc on July 06, 2011, 07:26:04 AM
Code:
<script>
var arrs = ["test1","test1","test1","test1"];
for (var i=0;i<arrs.length;i++) {
  $("#div_menu").menu({
     text:arrs[i],
     onclick:function() {alert("ok")}
  });
}
</script>
<div id="div_menu" style="width:100px;"></div>

with this code, I want to alert "ok" by clicking the menu.but i just get wrong:the alert function just fires once when the menu initialized,bu no function by clicking the menu.


Title: Re: Problem with menu appendItem
Post by: stworthy on July 06, 2011, 06:40:37 PM
Create the menu first and then call 'appendItem' method to append menu item to your menu.

The easiest way to create menu is to add 'easyui-menu' class attribute to a <div/> markup, just like this:
<div id="div_menu" class="easyui-menu" style="width:100px;"></div>

Now you can call the 'appendItem' method:
Code:
var arrs = ["test1","test1","test1","test1"];
for (var i=0;i<arrs.length;i++) {
  $("#div_menu").menu('appendItem', {
     text:arrs[i],
     onclick:'javascript:alert("ok")'
     // or
     // handler:function() {alert("ok")}
  });
}