gpt4 book ai didi

jquery - 将 ID 作为值与自动完成中的文本绑定(bind)

转载 作者:行者123 更新时间:2023-12-03 22:29:58 26 4
gpt4 key购买 nike

我正在使用 Kendo 自动完成,因为我正在填充文本并使用该文本解析数据,但我想使用 ID 作为值将其发送到表单提交的服务器端。

我正在使用此 Kendo 编辑器,但无法将“CustomerID”绑定(bind)为自动完成的值::

 @(Html.Kendo().AutoComplete()
.Name("Customers")
.DataTextField("CustomerShortName")
.Value("CustomerID")
.Filter("contains")
.MinLength(3)
.Template("<label>${ data.CustomerShortName }</label>")
.HtmlAttributes(new { disabled="disabled" })
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCustomers", "GetData");
})
.ServerFiltering(true);
})
)

请尽快帮助我。

最佳答案

我用另一种方式做到了这一点,我为其 ID 值创建了一个隐藏类型,即“CustomerID”为

@Html.HiddenFor(x=>x.CustomerID)

关于剑道自动完成的更改,我编写了一些事件,

    @(Html.Kendo().AutoComplete()
.Name("Customers")
.DataTextField("CustomerShortName")
.Events(events => events.Select("CustomerSelect"))
.Filter("contains")
.MinLength(3)
.Template("<label>${ data.CustomerShortName }</label>")
.HtmlAttributes(new { disabled="disabled" })
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCustomers", "GetData");
})
.ServerFiltering(true);
})
)

为此,我使用 Javascript 函数作为::

<script>
//Set CustomerID
function CustomerSelect(e)
{
var DataItem = this.dataItem(e.item.index());
$("#CustomerID").val(DataItem.CustomerID);
}
</script>

我在提交表单时使用的值。感谢您的帮助。

关于jquery - 将 ID 作为值与自动完成中的文本绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20234069/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com