Javascript 如何基于其他下拉数据加载Jqgrid下拉列表?

Javascript 如何基于其他下拉数据加载Jqgrid下拉列表?,javascript,jquery,asp.net-mvc,razor,jqgrid,Javascript,Jquery,Asp.net Mvc,Razor,Jqgrid,我的屏幕上有两个下拉列表,一个是普通剃须刀下拉列表,另一个是Jqgrid下拉列表。Razor下拉代码如下所示: <div class="col-md-4"> <label for="" class="control-label">Loan Currency</label><br /> @Html.DropDownListFor(m => m.LoanCurrency, Model.Currencies.ToSelectLis

我的屏幕上有两个下拉列表,一个是普通剃须刀下拉列表,另一个是Jqgrid下拉列表。Razor下拉代码如下所示:

 <div class="col-md-4">
    <label for="" class="control-label">Loan Currency</label><br />
    @Html.DropDownListFor(m => m.LoanCurrency, Model.Currencies.ToSelectListItems(x => x.CurrencyCode, x => x.Id.ToString(), "", true, "", "Select"), new { @class = "form-control" }).DisableIf(() => Model.IsReadOnly == true)
    @Html.HiddenFor(m => m.LoanCurrency)
</div> 
当我在我的网格中单击Addnew按钮时,如果Jqgrid下拉列表不为空,那么它应该自动填充razor dorpdown的数据。Jqgrid下拉列表从名为Currency的变量加载,如下所示

var Currencies = $.ajax
                ({
                    type: 'POST',
                    async: false,
                    url: RootUrl + "ECB/GetJsonCurrencies",
                    cache: true,
                    contentType: 'application/json; charset=utf-8',
                    success: function (result) {
                        if (!result) alert('No Currencies Found!!!');
                    },
                    error: function (error) {
                        alert('Failure to retrieve Json.' + error.toString() + "~~~" + error.ErrorMessage);
                    }
                }).responseText;

In which the GetJsonCurrencies method return a Json Currency list. 

选择razor下拉列表后,用户需要在网格中提供详细信息,因此当用户单击网格中的addnew按钮时,Jqgrid下拉列表应自动填充razor下拉列表中选择的值。如何操作?

您可以在
editoptions
中使用
dataInit
,如下所示。执行
ajax
调用
dataInit
函数添加填充下拉列表。希望这对你有帮助

{
    name: 'CurrencyName',
    index: 'CurrencyName',
    width: 120,
    editable:true,
    edittype: 'select',
    editoptions: { dataInit : function (elem) { 
          var curr = $('#LoanCurrency').val(); //dropdown outside jqgrid value
          if(curr){
              //Your ajax call goes here and populate dropdown with 
              //by the data of ajax call like following.
              $(elem).empty();
              $(elem).append('<option>Currency name 1</option>');
              $(elem).append('<option>Currency name 2</option>');
              $(elem).append('<option>Currency name 3</option>');
          }
       } 
    } 
}
{
名称:“CurrencyName”,
索引:“CurrencyName”,
宽度:120,
是的,
edittype:'选择',
编辑选项:{dataInit:function(elem){
var curr=$('#LoanCurrency').val();//在jqgrid值之外的下拉列表
如果(当前){
//您的ajax调用将转到此处,并使用
//通过ajax调用的数据,如下所示。
$(elem).empty();
$(elem).append('Currency name 1');
$(elem).append('Currency name 2');
$(elem).append('Currency name 3');
}
} 
} 
}
Js小提琴:

var Currencies = $.ajax
                ({
                    type: 'POST',
                    async: false,
                    url: RootUrl + "ECB/GetJsonCurrencies",
                    cache: true,
                    contentType: 'application/json; charset=utf-8',
                    success: function (result) {
                        if (!result) alert('No Currencies Found!!!');
                    },
                    error: function (error) {
                        alert('Failure to retrieve Json.' + error.toString() + "~~~" + error.ErrorMessage);
                    }
                }).responseText;

In which the GetJsonCurrencies method return a Json Currency list. 
{
    name: 'CurrencyName',
    index: 'CurrencyName',
    width: 120,
    editable:true,
    edittype: 'select',
    editoptions: { dataInit : function (elem) { 
          var curr = $('#LoanCurrency').val(); //dropdown outside jqgrid value
          if(curr){
              //Your ajax call goes here and populate dropdown with 
              //by the data of ajax call like following.
              $(elem).empty();
              $(elem).append('<option>Currency name 1</option>');
              $(elem).append('<option>Currency name 2</option>');
              $(elem).append('<option>Currency name 3</option>');
          }
       } 
    } 
}