在$.ajax({
我返回带有值的标签,但我想要第一个标签下面的第二个标签,我尝试了+ "\n" +
。一个更好的问题是我如何在那里插入html
?因为以后可能我想插入表格或其他东西看起来不错。
这是脚本:
<script type="text/javascript">
$(document).ready(function () {
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
$("#search").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Jobs/GetTags",
type: "POST",
dataType: "json",
data: { term: extractLast(request.term)},
success: function (data) {
response($.map(data, function (item) {
return {
label: item.Name + "\n" + item.Description,
value: item.Name,
};
}))
}
})
},
focus: function () {
return false;
},
search: function () {
// custom minLength
var term = extractLast(this.value);
if (term.length < 2) {
return false;
}
},
select: function (event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(", ");
return false;
},
messages: {
noResults: '',
results: function () { }
}
});
})
这是剃刀:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<p>
Tags @Html.TextBox("search")
</p>
}
答案 0 :(得分:0)
发现它!
我在最后添加:
}).data("ui-autocomplete")._renderItem = function (li, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.label1 + "</a>" + "<br />" + item.label2 + "</a>").before("<br />")
.appendTo(li);
};