1

使用 Jquery 允许用户在输入字段中使用“远程感知”,这将显示“客户”列表......

一切正常,但是当我希望用户编辑记录时,我需要知道如何设置字段的初始值(给存储的客户)......感谢任何帮助......

<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>
4

0 回答 0