欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Kendo UI dropdownlist 后台绑定默认值

程序员文章站 2022-06-11 22:41:39
...
                               <div style="display:block;float:left;width:100%;min-width:175px;height:80%;margin-top:7px">
                                    <input id="Exp_Position" inputRequired="required" onblur="inputRequiredChange(this)"
                                           data-role="dropdownlist"
                                           data-text-field="Exp_PositionName"
                                           data-value-field="Exp_PositionID"
                                           data-filter="contains"
                                           data-bind="value:expenseApply.Exp_PositionID, source:PositionResource,events:{change:PositionChange}">
                                    <span class='k-widget k-tooltip k-tooltip-validation field-validation-error k-required' style="display:none;position: absolute;top: 90%;left: 0;">职务不能为空</span>
                                </div>
 //职务数据源
        PositionResource: new kendo.data.DataSource({
            transport: {
                read: {
                    url: "/BaseData/PositionList"
                }
            },
            schema: {
                model: {
                    id: "Exp_PositionID"
                }
            },
            requestEnd: function (res) {
                if (res && res.response && res.response.length > 0) {
                    var defaultPosition = _.find(res.response, function (t) {
                        return t.IsDefault;
                    });
                    console.log(expenseApplyCreateViewModel.expenseApply);
                    if (defaultPosition) {
                        expenseApplyCreateViewModel.expenseApply.set("Exp_PositionID", defaultPosition.Exp_PositionID);
                        expenseApplyCreateViewModel.expenseApply.set("Exp_PositionName", defaultPosition.Exp_PositionName);
                    }
                }
            }
        }),
/// <summary>
        /// 职务数据源
        /// </summary>
        /// <returns></returns>
        [Data]
        public ActionResult PositionList()
        {
            ExpInnerOrderService proc = new ExpInnerOrderService();
            List<CndModel> pars = new List<CndModel>();
            //pars.Add(new CndModel("(USER_CODE  = '" + UserContext.UserID + "')"));
            var result = proc.GetExpOraclePositionList( pars, "order by JOB_CID ");

            if (!result.IsNullOrCountZero())
            {
               var defaultPosition= result.FirstOrDefault();
                defaultPosition.IsDefault = true;
            }

            result.SetRowindx();
            return Json(result, JsonRequestBehavior.AllowGet);
        }