0

This is my code, it works perfect without using array, and creates context menu on div, but now i want to create some context menu items from array. when i apply array it is showing all items of array in one line and separates by Comma (,) . but i need all items in different rows.

http://jsfiddle.net/danial786zz/sobnwgeb/ this fiddle is working perfect but i need to make items from array.

$('#div_id").chromeContext({
items: [

      { title: array,         onclick: function () { RToTb(array_name) } },
      { title: 'properties'   onclick: function () { abc();            } },
      { title: 'view'         onclick: function () { def();            } }

    ]

});

2
  • 1
    I don't understand your question Commented Aug 29, 2014 at 6:12
  • Derek check my FIDDLE , right click on a div it will open small menu... i want to make that menu through array.. ( but in a fiddle you can see it is hardcoded ) Commented Aug 29, 2014 at 6:27

2 Answers 2

2

I think this will work for you :

I have created an array out of another array and used that in the context menu.

 $(function(){
    var arr = ['1st Row', '2nd Row', '3rd Row'];
    var menuitems = [];
    $.each(arr, function( index, value ) {
       menuitems[index] =  { title: value, onclick: function () { RToTb(array_name) }};
    });

    $('#div_id').chromeContext({
       items : menuitems
    });
});

FIDDLE

Sign up to request clarification or add additional context in comments.

4 Comments

Yes that is possible. In that case you have to make array of function names and use the array inside each in somewhat like onclick: function { functionname[i] } where functionname is an array containing names of functions. Haven't tried this. You can give it a try. Ask help if needed but before that please try by yourself first.
hi Yunus i am stuck in this little problem check this jsfiddle.net/danial786zz/ykL17tce it gives only last number when alert onclick
Hello.. This is another fiddle.. Check this out. jsfiddle.net/Yunus_Aslam/jg5ksyyv
you are really great..gud experiance you answer within minutes thanks, i am new going ahead if i got stuck i will message here thanks..
0

It is about your array definition. There should be objects inside each array element.

$(function(){
   var arr=[];
   arr[0]= { 'title': '1st row', 'onclick:': function () { RToTb(array_name); } };
   arr[1]={ 'title': '2st row', 'onclick:': function () { RToTb(array_name); }};
   arr[2]={ 'title': '3st row', 'onclick:': function () { RToTb(array_name); }};


   $('#div_id').chromeContext({
      items: arr
   });
});

Check the link below for working example: http://jsfiddle.net/v7v8f386/1/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.