swisnl / jQuery-contextMenu

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

Custom class-x vars on list elements (not just unordered lists) #639

Closed JohnCannonIT closed 6 years ago

JohnCannonIT commented 6 years ago

Kind of a sub-question from my prior question. I can get data-x variables to work just fine. But I can't get them to work when I put them on the list items (which is necessary, as there are dynamic elements that vary on the list item). How do I refer to them? I know options.$trigger.attr("data-apiguid") will refer to <ul data-apiguid="whatever> However, how do you refer to data- elements on <li> </li>? Example below:

`$(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" } } });

//$('.context-menu-AddFavorite').on('click', function (e) {
//    console.log('clicked', this);
//})

});`

<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>
                                                            @if (q.webapi_name == "Add Printer" ||
                                                                q.webapi_name == "Delete Printer" ||
                                                                q.webapi_name == "LaunchERBUtilities password" ||
                                                                q.webapi_name == "NsLookUp Detail" ||
                                                                q.webapi_name == "Ping IP Address" ||
                                                                q.webapi_name == "Delete Printer" ||
                                                                q.webapi_name == "Update LogLevel Key Value" ||
                                                                q.webapi_name == "Update Bridge Store Value" ||
                                                                q.webapi_name == "Update Screen Aspect Ratio" ||
                                                                q.webapi_name == "Get Scheduled Tasks Information" ||
                                                                q.webapi_name == "Get Running Processes")
                                                            {
                                                                <a href="#">
JohnCannonIT commented 6 years ago

It turns out that if I REPLICATE the context-menu-AddFavorite line inside <li data-apiguid=@q.webapi_guid>, it works. Not sure why I have to do that, but I'm not complaning.