我正在开发一个用于工作的javascript控件,并将其集成到grails插件中。所有插件只是根据taglib填充选项,如下所示:
$(document).ready(function() {
var ${name} = $("#${name}").tagInput({
$inputListener: $("#${inputListenerName}"),
$errorHandler: $("#${errorHandler}"),
$domainListener: $("#${domainListenerName}"),
errorClass: "${errorClass}",
validClass: "${validClass}",
caseSensitive: ${caseSensitive},
constraints: {
minSize: ${minSize},
maxSize: ${maxSize},
maxTags: ${maxTags},
validationRegex: "${tagRegex}"
},
errorMessages: {
size: "${sizeErrorMessage}",
regex: "${regexErrorMessage}",
maxTags: "${maxTagsError}"
},
responsive: {
length: ${maxTagLength},
lengthxs: ${maxTagLengthxs},
xsMode: ${xsWidth}
}
});
debugger;
});
评估时看起来像这样:
var emailTags = $("#emailTags").tagInput({
$inputListener: $("#invitesInput"),
$errorHandler: $("#inviteErrors"),
$domainListener: $("#null"),
errorClass: "label-danger",
validClass: "label-primary",
caseSensitive: false,
constraints: {
minSize: 1,
maxSize: 255,
maxTags: 100,
validationRegex: "[^@]+@[^@]+\.[^@]+"
},
errorMessages: {
size: "",
regex: "Must be a valid email string.",
maxTags: "You have entered too many recipients. Please send out invites before adding more recipients."
},
responsive: {
length: 50,
lengthxs: 20,
xsMode: 768
}
});
当Chrome访问调试器语句时,我有正确的对象。这是:
tagInput {parseTags: function, clear: function, serialize: function}
如果我离开这个,我立即输入jQuery,我的对象立即变成
div#emailTags.turningTags
最终变成
<div id="emailTags" name="emailTags" class="turningTags ">…</div>
如果有帮助,这是tagInput对象的当前代码。
https://gist.github.com/anonymous/e785ec24e0c1388cd599
为什么会这样?为什么我的对象被转换为这个HTML元素?我已经尝试更改变量的名称无济于事,无论我将此变量的名称更改为什么,它每次都会发生。我试过把它变成一个独立的对象,而不是一个jQuery函数,同样的事情仍然在发生。