简体   繁体   中英

jQuery tagit plugin, public methods

Does anyone know if the tagit jQuery plugin has a public method for removing just 1 specified tag from the list?

I saw there is for removing (clear) all tags from the list, but I would need to remove only 1 tag :P

Also, how to call all the public methods from outside of tagit() call?

No, it does not. Just wrap a public function around _popTag in the widget code, eg

removeTag : function(label,value) {
    this._popTag(label, value);
}

and call it like this:

$(myElement).tagit("removeTag", label, value);

If you're using the jQuery UI Tag-it plugin by aehlke , then these instructions will provide the plugin with this functionality:

Syntax:

// removes the tag called "outdated-tag"
$("#mytags").tagit("removeTagByName","outdated-tag");

Add this method right below the removeAll method in the tag-it.js file:

removeTagByName: function(tagName) {
        var that = this;
        this.removeTag(this.tagList.children('.tagit-choice').find("input[value='"+
                tagName +"']").parent(), null);
}

NOTE: You are modifying a code library! So be sure to document what you're doing with clear code comments and otherwise documenting this change so that when you or a colleague update the plugin to another version, you're sure to include this functionality and not be baffled by why things suddenly stopped working ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM