标签 - 它onlyAvalaibleTags选项不起作用 [英] Tag-it onlyAvalaibleTags option doesn't work
本文介绍了标签 - 它onlyAvalaibleTags选项不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用标签,它的插件从 https://github.com/aehlke/tag-it /下载的。如何禁用添加新的标签?
I use tag-it plugin from https://github.com/aehlke/tag-it/downloads. How to disable adding new tags?
$(document).ready(function () {
$("#Tags").tagit({
singleField: true,
singleFieldNode: $('#mySingleField'),
// onlyAvailableTags : true,
allowNewTags: false,
tagSource: [@Html.Raw(ViewBag.AvailableTags)]
});
});
我试图用 onlyAvailableTags:真正的
和 allowNewTags:假
选项,但没有效果。
推荐答案
既然你说,但没有效果,我猜想, @ Html.Raw(ViewBag.AvailableTags)
产生一个,打破了JavaScript语法的输出。该标签必须用引号引起来,否则会被作为变量处理。
Since you say "but there's no effect", I would guess that @Html.Raw(ViewBag.AvailableTags)
produces an output that that breaks the javascript syntax. The tags need to be in quotes, otherwise they are treated as variables.
Incorrrect输出:
Incorrrect output:
tagSource: [my-tag, another-tag]
服务器端,我假设你有某种的IEnumerable<串GT;
:
ViewBag.AvailableTags = new List<string>
{
"my-tag",
"another-tag",
};
然后,在你的 .cshtml
:
tagSource: ["@string.Join("\", \"", ViewBag.AvailableTags)"]
这将产生正确的输出:
tagSource: ["my-tag", "another-tag"]
这会是什么我想先试。
这篇关于标签 - 它onlyAvalaibleTags选项不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文