简体   繁体   English

jQuery tagit插件,公共方法

[英]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? 有谁知道tagit jQuery插件是否具有从列表中仅删除1个指定标签的公共方法?

I saw there is for removing (clear) all tags from the list, but I would need to remove only 1 tag :P 我看到可以从列表中删除(清除)所有标签,但是我只需要删除1个标签:P

Also, how to call all the public methods from outside of tagit() call? 另外,如何从tagit()调用外部调用所有公共方法?

No, it does not. 不,不是的。 Just wrap a public function around _popTag in the widget code, eg 只需在小部件代码中将_popTag周围包装一个公共函数,例如

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: 如果您使用的是aehlkejQuery UI Tag-it插件 ,那么以下说明将为插件提供此功能:

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: 在tag-it.js文件中的removeAll方法下面添加此方法:

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 ;) 因此,请务必用清晰的代码注释记录您的工作,并以其他方式记录此更改,以便当您或同事将插件更新到另一个版本时,您一定要包括此功能,而不必为突然停止的原因所困扰工作;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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