2017-07-25 88 views
0

我一直在做大量的搜索,並且似乎找不到任何可用的示例。Telerik MVC層次結構網格,編輯器彈出窗口,在JavaScript事件中獲取父數據

我將簡化代碼,因爲我有一個非常大的telerik mvc層次結構網格。這是一個兒童模板的幾個級別,我需要上一級的父級信息。

<script id="leagueTemplate" type="text/kendo-tmpl"> 
       @(Html.Kendo().Grid<LeagueViewModel>() 
      .Name("grid_#=LeagueTypeId#") 
      .ToolBar(toolbar => 
      { 
       toolbar.Create().Text("Add New League(Window)"); 
      }) 
      .Events(e => e.Edit("leagueEdit")) // this function runs 
      .DataSource(dataSource => dataSource 
       .Ajax() 
       .Model(model => model.Id(p => p.LeagueID)) 
       .Read(read => read.Action("Bound_League_Read", "Configuration", new { _leagueTypeId = "#=LeagueTypeId#" })) 
       .Create(create => create.Action("League_Create", "Configuration").Data("getHeirarchyData")) // this function doesnt run 
      ) 
       ) 
</script> 

      function getHeirarchyData() { 
        console.log("get heirachy data"); // never runs 
      } 

      function leagueEdit(e) { 

       // this runs 
       // not sure how to get parent data from e 

       } 

回答

0

有可能是解決這個更好的方式,如果是這樣我會檢查你的答案,但也許這將幫助別人在其間。

我解決了這個問題,通過設置模型的默認值,除了僅用於字符串值,因爲我必須以模板語法字符串的形式訪問這些值,所以該模型非常出色。所以我只是將我的層次結構字段的字符串值等效添加到模型中。

  .Model(model => 
       { 
       model.Id(p => p.LeagueID); 
       model.Field(l => l.strSportId).DefaultValue("#=SportId#"); 
       model.Field(l => 
       l.strLeagueTypeId).DefaultValue("#=LeagueTypeId#"); 
       } 
      ) 

然後當我打電話給編輯功能,我能得到的值是這樣的:

function leagueEdit(e) { 
    var sportId = parseInt(e.model.strSportId); 
    var leagueTypeId = parseInt(e.model.strLeagueTypeId); 
} 
相關問題