0

我正在实现两个下拉列表,其中通过选择“关闭日期”下拉列表(级联)填充“基金”下拉列表。问题是在 Ajax 更新后,“基金”下拉列表显示一个空白值,而不是第一个选择。我验证了返回的选项将第一个项目标记为“已选择”。我还尝试了一些方法来默认更新后下拉列表的选定索引。那么,如何在更新后将下拉菜单默认为特定的选择。下面列出了定义下拉列表和选择“关闭日期”时运行的 javascript 函数的代码片段。

使用 Telerik 2011.1.315 和 JQuery 1.5.1

<script type="text/javascript">
    fundListUrl = '<%= Url.Action("GetFundList","Admin") %>'
    function GetFundList(e)
    {
        var fundDropDown = $('#FundId');
        var fundDropDownData = fundDropDown.data('tDropDownList');
        fundDropDownData.loader.showBusy();
        $.get(fundListUrl, { dateId: e.value }, function (data) {
            fundDropDownData.dataBind(data);
            fundDropDownData.loader.hideBusy();
            fundDropDown.attr('selectedIndex', 0); // Not Working
        });
    }
</script>

...

<table>
    <tr>
    <td class="editlabel">Close Date:</td>
    <td>
        <%= Html.Telerik().DropDownListFor(o => o.ReportingPeriodDateId)
            .BindTo((SelectList)ViewData["closeDateList"])
            .ClientEvents(events => events.OnChange("GetFundList"))
        %>
    </td>
    </tr>
    <tr>
    <td class="editlabel">Fund:</td>
    <td>
        <%= Html.Telerik().DropDownListFor(o=>o.FundId)
            .BindTo((SelectList)ViewData["fundList"])
            .HtmlAttributes(new { style = "width: 40em;" })
        %>
    </td>
    </tr>
</table>
4

1 回答 1

1

您应该能够通过其索引或其值(如果您事先为组合框项定义值)选择一个组合项,如下所示:

<script type="text/javascript">
    fundListUrl = '<%= Url.Action("GetFundList","Admin") %>'
    function GetFundList(e)
    {
        var fundDropDown = $('#FundId');
        var fundDropDownData = fundDropDown.data('tDropDownList');
        fundDropDownData.loader.showBusy();
        $.get(fundListUrl, { dateId: e.value }, function (data) {
            fundDropDownData.dataBind(data);
            fundDropDownData.loader.hideBusy();
            fundDropDown.select(0); // select first combo item, or use fundDropDown.value('0') in case the first combo item has value set to 0
        });
    }
</script>
于 2011-05-19T15:43:00.720 回答