所以我有这个代码
$(document.body).on('click', '.btn-create-tournament', function () {
var title = $(".create-tournament-title").val();
var format = $(".create-tournament-format").val();
var sport = $(".create-tournament-sport").val();
var prize = $(".create-tournament-prize").val();
var date = $(".create-tournament-date").val();
var location = $(".create-tournament-location").val();
var teams = $(".create-tournament-teams").val();
$.post('/Tournament/Create', {
title: title,
format: format,
sport: sport,
prize: prize,
date: date,
location: location,
teams: teams
}, function (response) {
if (response > 0) {
window.location.href = "/Tournament/Details/" + response;
}
})
}).on('input', '.search-teams', function () {
var query = this.value;
$.get('/Teams/Search', { name: query }, function (response) {
$('.search-team-results').html($(response).find('.team-results-search').html());
})
})
然后调用这里的input函数
@model List<TeamViewModel>
<div class="search-team-results">
@foreach (var item in Model)
{
<div>
<label class="team-results-search" data-team-id="@item.Id">@item.Name</label>
</div>
}
</div>
最后它到达那里
<h6>Players</h6>
<div class="form-outline">
<input class="search-teams" type="search" placeholder="Type query" aria-label="Search" />
<div class="search-team-results">
</div>
</div>
因此,我在输入字段中搜索团队,但它们在字段下方仅显示为标签,我的问题是如何编写脚本,将它们实际添加到视图模型中的列表中?
1条答案
按热度按时间7fhtutme1#
将只获取结果列表中第一个标签的内部html(在本例中为文本)。要获取整个列表,请使用