使用Jquery允许用户在输入字段中使用“telesense”,这将显示“客户”列表......
一切正常,但是当我希望用户编辑记录时,我需要知道如何设置字段的初始值(对存储的客户)...任何帮助赞赏.....
<div class="form-group">
<input type="text" id="customer" name="customer"/>
<input type="hidden" id="ClientAccount_Id" name="ClientAccount_Id"/>
</div>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
var customers = [
@{
bool addComma = false;
foreach (ACCS.StockControl.Models.ClientAccount customer in Model.AllClients)
{
if (addComma)
{
<text> @Html.Raw(",") </text>
}
<text> @Html.Raw(string.Format("{{ value: \"{0}\", label: \"{1}\" }}", customer.Id, customer.CompanyName)) </text>
addComma = true;
}
}
// Example target layout ....
// "customer1",
// "customer2",
// "customer3"
];
$("#customer").autocomplete({
minLength: 0,
source: customers,
focus: function (event, ui) {
$("#customer").val(ui.item.label);
return false;
},
select: function (event, ui) {
$(this).val(ui.item.label).change();
$("#ClientAccountId").val(ui.item.value);
return false;
}
}
});
});
</script>