本文介绍了自动完成源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的形式自动完成2文本框。我想要做的是动态变化二号自动完成文本框的源代码,如果一个值已经从第一个选择的。

I have 2 autocomplete text boxes on my form. What I want to do is dynamically change the source on the 2nd autocomplete textbox if a value has been selected from the first.

我标记的片断如下:

 $(function () {
    $("#SelectedAddress").autocomplete({
        source: "/CreateFIS/GetProperties",
        select: function(event, ui) {
            if (ui.item) {
                event.preventDefault();
                $('#SelectedAddress').val(ui.item.label);
                $('#SelectedAddressId').val(ui.item.value);
                getPropertyInformation(ui.item.value);
            }
        },
        focus: function(event, ui) {
            if (ui.item) {
                event.preventDefault();
                $('#SelectedAddress').val(ui.item.label);
                $('#SelectedAddressId').val(ui.item.value);
                //getPropertyInformation(ui.item.value);
            }
    }
    });
});

$(function () {
    $("#SelectedScheme").autocomplete({
        source: "/CreateFIS/GetSchemes",
        select: function (event, ui) {
            if (ui.item) {
                event.preventDefault();
                $('#SelectedScheme').val(ui.item.label);
                $('#SelectedSchemeId').val(ui.item.value);
            }
        },
        focus: function (event, ui) {
            if (ui.item) {
                event.preventDefault();
                $('#SelectedScheme').val(ui.item.label);
                $('#SelectedSchemeId').val(ui.item.value);
            }
        }
    });
});


<tr>
                    <td style="width:200px;"><label for="addresses">Please Select A Scheme</label> </td>
                    <td style="width:600px;">@Html.TextBoxFor(model => model.SelectedScheme, new { @class = "largeTextBox" })</td>
                    <td style="width:200px;"> @Html.ValidationMessageFor(model => model.SelectedSchemeId) </td>
                </tr>
                <tr>
                    <td style="width:200px;"><label for="addresses">Please Select A Property </label> </td>
                    <td style="width:600px;">@Html.TextBoxFor(model => model.SelectedAddress, new { @class = "largeTextBox" })</td>
                    <td style="width:200px;"> @Html.ValidationMessageFor(model => model.SelectedAddressId) </td>
                </tr>

什么是acomplish最好的方法?

WHat is the best way to acomplish this?

推荐答案

使用选项方法来更改源:

var source = $(".selector").autocomplete("option", "source", "/New/Source");

这篇关于自动完成源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:48