swisnl / jQuery-contextMenu

jQuery contextMenu plugin & polyfill
https://swisnl.github.io/jQuery-contextMenu/
MIT License
2.24k stars 744 forks source link

Getting data- variables from <li> #641

Closed JohnCannonIT closed 6 years ago

JohnCannonIT commented 6 years ago

My problem is only this last variable - data-apigiud, That is dependent on the for loop, which means I can't put it inside the <ul> tag. I've tried putting it in the <li>within the loop (as below) and in the href below that, but it the value isn't passing. It is for all the data-vars inside the <ul> tag. How do you reference the data-vars in the <li> tag?

URL:
http://localhost:45023/Stores/WorkstationIndividual/10.230.244.19/59124?mac=78:AC:C0:AD:FF:14&APIFavoritesFlag=add&APIguid=undefined

View:

<ul class="sf-menu-ajdusted context-menu-AddFavorite" data-ipaddress=@Model.ipaddress
                                                  data-storeNbr=@Model.store data-mac=@Model.mac>
   @foreach (var q in Model.APIInfoVMInfo.Where(a => a.category == n && a.sub_category == p))
    {
          <li data-apiguid=@q.webapi_guid>
      ...... etc.

Javascript:

function () {
    $.contextMenu({
        selector: '.context-menu-AddFavorite',
        // Make the context menu appear above superfish hover
        zIndex: function () {
            return 990;
        },
        callback: function (key, options) {
            //var mac = '78:AC:C0:AD:FF:14';
            //var storeNbr = '59124';
            //var ipaddress = '10.230.244.19';
            var ipaddressPrefix = '/Stores/WorkstationIndividual/';
            var ipaddress = options.$trigger.attr("data-ipaddress");
            var storeNbrPrefix = '/';
            var storeNbr = options.$trigger.attr("data-storeNbr");
            var macPrefix = '?mac='
            var mac = options.$trigger.attr("data-mac");        
            var APIFavoritesFlag = '&APIFavoritesFlag=' + key;
            var apiguidPrefix = '&APIguid=';
            var apiguid = options.$trigger.attr("data-apiguid");
            var link = ipaddressPrefix + ipaddress + storeNbrPrefix + storeNbr + macPrefix + mac + 
  APIFavoritesFlag  + apiguidPrefix + apiguid;
            window.location.href = link;
        },
        autoHide: true,
        items: {
            "add": { name: "Add to Favorites", icon: "add" }
        }
    });

Thank you for your help.

John C

JohnCannonIT commented 6 years ago

Well, I figured out that what I want is the Original Event.