Semantic-UI: adding .api using wildcard selector and get access to the specific element

你说的曾经没有我的故事 提交于 2019-12-13 00:53:10

问题


As seen here the selectors id #username is binded twice and nested. In the first binding, the value can be set with $(this).val(); and the be used in the second, nested binding for the Semantic-UI API.

But what if I have several elements like element_1, element_2 etc?

Right now, I'm using this code, but the event is fired for each element that matches the wildcard [id^=unbind_]and not only (like it should be) for the clicked element:

$(document).on('click','[id^=unbind_]', function(){
    var permission=$(this).attr('data-value');
    var id=$(this).attr('id');
    var role_id=$(this).attr('data-roleid');
    //console.log('Permission:' + id);
    $('[id^=unbind_]')
        .api({
            action: 'unbind permissions',
            on: 'now',
            method: 'DELETE',
            data: { 'permission': permission},
            onSuccess: function(data) {
                console.log('SUCCESS: ' + id);
                remove_element(id);
                decr('#role_cnt_' + role_id);
            }
        });
});

来源:https://stackoverflow.com/questions/49508257/semantic-ui-adding-api-using-wildcard-selector-and-get-access-to-the-specific

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!