【问题标题】:Pass additional parameter during Expand event for Kendo Treeview在 Kendo Treeview 的 Expand 事件期间传递附加参数
【发布时间】:2013-01-12 11:54:20
【问题描述】:

我有一个剑道 Gridview 与 Treeview 在同一页面上。 Gridview 包含与当前用户关联的客户端行。当Gridview中的一个客户端行被选中时,我触发Treeview再次读取DataSource(selectedClient是一个js变量,当Gridview中的一行被选中时设置):

$("#folderTreeView").data("kendoTreeView").dataSource.read({ userId: _selectedClient })

TreeView 的重新绑定工作完美。问题是当新的 TreeView 具有带有嵌套文件夹的文件夹结构时。单击“展开”图标时,只传递了item的id,但我还需要从GridView传递当前选择的客户端(存储在_selectedClient中)。

那么,有没有办法在“expand”事件期间或以其他方式将附加参数(在这种情况下为 userId/_selectedClient)添加到“whatever”传递给服务器?

控制器

[HttpPost]
public virtual JsonResult List(int? userId, int? id)
{
 ....
}

剃须刀

@(Html.Kendo().TreeView()
    .Name("folderTreeView")
    .DataTextField("Name")
    .DataSource(dataSource => dataSource
        .Read(read => read.Action("List", "Folder", new { area = "Portal"           }).Type(HttpVerbs.Post)
        )
    )
    .Events(events => events
        .Expand("onSelect")
        )
)

【问题讨论】:

    标签: asp.net-mvc razor kendo-ui kendo-treeview


    【解决方案1】:

    我今天发现了这个,它适用于 Grid,但我假设它适用于使用 DataSource 的任何其他东西:

    @(Html.Kendo().Grid<MvcApplication1.Models.Product>()
    .Name("Grid")
    .DataSource(dataSource => dataSource
        .Ajax()
        .Read(read => read.Action("Products_Read", "Home")
            .Data("additionalData") // the name of the JavaScript function which will return the additional data
        )
    )
    .Pageable()
    )
    <script>
    function additionalData() {
        return {
            firstName: "John",
            lastName: "Doe"
        };
    }
    </script>
    

    The Kendo Docs这里阅读更多...

    【讨论】:

      【解决方案2】:

      我终于找到了—— http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/migration/widgets/treeview

      DataSource 事件如下所述...

      <script>
        function addData(data) {
          return { userId: _selectedClient };
        }
      </script>
      
      <div class="demo-section">
        @(Html.Kendo().TreeView()
              .Name("folderTreeView")
              .DataTextField("Name")
              .DataSource(dataSource => dataSource
                  .Read(read => read
                    .Action("List", "Folder", new { area = "Portal" })
                    .Type(HttpVerbs.Post)
                    .Data("addData")
                  )
              )
          )
      </div>
      

      【讨论】:

      • 您的Folder 参数需要哪些参数才能使其工作? areafirstNamelastName?执行此操作时,我没有收到任何其他数据。
      • Richie - 我在 .net 中使用 MVC 模式。因此,“.Action”正在构建一个链接以访问我的应用程序中的特定区域、控制器和方法([server.tld]/Portal/Folder/List)。在本例中,我的控制器中的“List”方法将接受 2 个参数:“id”(这是 Kendo 自动传递的文件夹 id)和“userId”,这是我使用 .Data 扩展名添加的附加自定义参数(它调用js函数“addData”并读取我定义的全局js变量(_selectedClient)。所以我只将两个参数传递给服务器,id和userId。帮助?
      猜你喜欢
      • 1970-01-01
      • 2011-07-10
      • 2017-12-08
      • 1970-01-01
      • 2019-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多