1. 程式人生 > >用JavaScript獲取聯動

用JavaScript獲取聯動

selected wget nbsp html allow branch als 聯動 val

<script>
        //聯動查詢
        $(function () {
            $("#BranchName").change(function () {
                var parent = $("#BranchName option:selected").val();
                if (parent != "" && parent !=0 ) {
                    $.ajax({
                        url: "/Store/GetStore?branchId=" + $("#BranchName option:selected").val(),
                        type: "get",
                        success: function (data) {
                            if (data.Data.length > 0) {
                                var op = "";
                                for (var i = 0; i < data.Data.length; i++) {
                                    op += "<option  value=" + data.Data[i].Id + ">" + data.Data[i].DealerName + "</option>"
                                }
                                $("#DealerName").html(op);
                                
                            }
                            if (data.Data == "") {
                                var option = "<option></option>"
                                $("#DealerName").html(option);
                            }
    
                        }
                    });
                } else {
                    eqlee.showWarring("請選擇分公司和經銷商");
                    $("#DealerName").html("<option> 請選擇</option>");
                }

            });
        });
    </script>

  

上面是實現聯動腳本

        public JsonResult GetStore(Guid branchId)
        {
            var data = new Models.ReturnJson() { Error = false };

            var filter = string.Format(" Deleted = 0 and branchId = ‘{0}‘",branchId);
            var dealerModel = _bllDealer.List(where: filter);
            var id = dealerModel.Select(x => x.Id);
            var dealerName = dealerModel.Select(x => x.DealerName);

            data = new Models.ReturnJson() { Error = false, Data = dealerModel };

            return JsonNet(data, behavior: JsonRequestBehavior.AllowGet);
        }

  上面是後臺獲取聯動的方法

以上是獲取聯動的方法,因為沒有時間細寫,只能簡便點。

用JavaScript獲取聯動