【发布时间】:2013-08-14 20:04:53
【问题描述】:
在页面加载时我有一个令牌输入,即,
$('.txtWard').tokenInput(ward, {
theme: 'facebook',
allowCustomEntry: true,
preventDuplicates: true,
tokenDelimiter: '*',
searchingText: 'Searching...'
});
但问题是,当我单击另一个按钮时,我想将项目预填充到此令牌输入文本框。当我使用以下代码时,文本框复制为另一个文本框。
$(document).ready(function () {
$('.txtWard').tokenInput(ward, {
theme: 'facebook',
allowCustomEntry: true,
preventDuplicates: true,
tokenDelimiter: '*',
searchingText: 'Searching...'
});
$('#btnGet').click(function () {
var prepopulateWards = new Array();
$.ajax({
type: "POST",
url: "FetchWard",
data: JSON.stringify({ patientNo: $('#txtPatientNo').val(), locale: 'en-US' }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
for (var j = 0; j < result.wards.length; j++) {
prepopulateWards.push({ id: result.wards[j].Code, name: result.wards[j].ward });
}
}
});
$('.txtWard').tokenInput(ward, {
theme: 'facebook',
allowCustomEntry: true,
preventDuplicates: true,
tokenDelimiter: '*',
searchingText: 'Searching...',
prePopulateFromValue: true,
prePopulate: prepopulateWards
});
});
});
【问题讨论】:
-
您能发布您在
prepopulateWards变量中存储的内容,以便我们提出建议吗?但是,是的,我认为您并不是要创建两次 tokenInput。 -
@Chris 请检查已编辑的问题
-
如果 Lee 下面的解决方案不正确,那么我认为您误解了 prePopulate 的使用方式。添加病房时,您在寻找什么活动?您希望它们在文本框中显示为标记,还是只想将它们添加到可搜索项目列表中? PrePopulate 适用于您在首次加载 TokenInput 时想要放置的令牌,否则就像 Lee 所说的“添加”,似乎是您所追求的解决方案。