我在一个ASP上工作。NET Web API。当我使用jQueryAjax请求调用Webneneneba API时,我会遇到问题。
我的问题是用斜线分隔的自动完成结果显示:
Id - Name - Designation
但我需要得到的预期结果是:
Id : 121
Name : michel nicol
Designation : It Manager
意味着我需要展示
Id
在第一行和第二行我都有
Name
第三行包含
Designation
.
因此,每个属性都将在一行上,而不是使用分隔的斜杠。
完整代码详细信息:
$("#txtDirectManagerId").autocomplete({
source: function (request, response) {
var searchTextDirectManager = $("#txtDirectManagerId").val();
console.log("search text" + searchTextDirectManager)
$.ajax({
url: '@Url.Action("GetAllEmployeeBasedSearchTextDirectManager", "Resignation")',
data: { searchTextDirectManager: searchTextDirectManager },
method: "GET",
dataType: "json",
success: function (data) {
response($.map(data, function (item) {
label: "File No : " + item.EmployeeID + " - " + "Name :" + item.EmployeeName + " - " +
"Designation : " + item.Designation, value: item.EmployeeID, employeeName: item.EmployeeName
};
}))
}
});
},
position: { my: "right top", at: "right bottom" },
appendTo: '#searchContainerDirector',
select: function (event, ui) {
$("#DirectManagerName").val(ui.item.employeeName);
},
minLength: 4,
});
用于自动完成的HTML控件:
<div class="col-md-7">
@Html.EditorFor(model => model.LineManager, new { htmlAttributes = new { @class = "form-control", id = "txtLineManagerId" } })
<div id="searchContainer">
</div>
</div>
<div class="col-md-7">
</div>
用于生成自动完成的脚本版本
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" type="text/javascript"
language="javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
更新的答案:
你能告诉我如何修改我的代码以在第二行、第二行和第三行显示id吗
任命
按代码选择