开发者

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 lis开发者_开发知识库t?

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, e.g.

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 ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜