【问题标题】:setting up kendo ui dropdownlist based on condition根据条件设置 kendo ui 下拉列表
【发布时间】:2013-11-19 00:56:38
【问题描述】:

如果 ViewBag.ServerId 中的值然后设置为 2,我想将以下下拉列表设置为某个值

    <script type="text/javascript">
     $(document).ready(function () {
        var data = [
                        { text: "Selection 1", value: "1" },
                        { text: "Selection 2", value: "2" }

        ];

 $("#Cust").kendoDropDownList({

                    dataTextField: "text",
                    dataValueField: "value",
                    dataSource: data,
                    index: 0,
                    optionLabel: {
                        text: "Please Select",
                        value: ""
                    }



                });
        var dropdownlist = $("#Cust").data("kendoDropDownList");

        });


    </script>

    <div>
    @if (ViewBag.serverId == 3)
    {
        so i would like to do something like this however i could reference dropdownlist.
        dropdownlist.select(dropdownlist.ul.children().eq(2));
    }
    else
    {


    }
    </div>

【问题讨论】:

    标签: razor kendo-ui


    【解决方案1】:

    您可以调整您的选择,例如:

    <script>
        $(document).ready(function () {            
    
            $("#Cust").kendoDropDownList({    
                ...
                index: (parseInt(@ViewBag.ServerId) === 3) ? 2 : 0,
                ...
            });
        });
    </script>
    

    【讨论】:

      【解决方案2】:
      I think you can do like this:
      
      @if (ViewBag.serverId == 3)
          {
      
      <script type="text/javascript">
              $(function() {
                 $("#Cust").data("kendoDropDownList").select(dropdownlist.ul.children().eq(2));
              });
              </script>
          }
      
          else
          {
      
      
          }
      You know, if there are mutiple jQuery dom ready event in one page. They will be executed by order.
      If the Kendo dropdown list component initialized in the prev context, I think you get the component instance from the element.
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-27
        • 1970-01-01
        • 2014-05-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多