1
<%:
    Html.Telerik().TreeView()
    .Name("ZebTree")
    .ExpandAll(false)
    .ClientEvents(events => events.OnSelect("TreeView_onSelect"))
    .BindTo(Model , map =>
            {
                map.For<TreeViewBind.Models.Category>(bind => bind.ItemDataBound((item, category) => { item.Text = category.CategoryName; }).Children(category => category.Products));
                map.For<TreeViewBind.Models.Product>(bind => bind.ItemDataBound((item, product) => { item.Text = product.ProductName;}));
            }        
    )
%>

上記は、telek mvc でツリーを生成するためのコードです。ノードを選択してアクションを実行したい。誰かが特定のノードをクリックすると、約ページに移動し、そのノードのテキストを引数として約ページに渡します。

4

2 に答える 2

2

OnSelect プロトタイプ:

function TreeView_onSelect(e) {

}

e には、選択された LI 要素である "item" という 1 つの要素しかありません。したがって、例は次のようになります。

function TreeView_onSelect(e) {
    alert($(e.item).text());
}

ここを参照してください: http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-treeview-client-api-and-events.html#ClientEvents

于 2012-08-01T04:48:30.163 に答える
1

皆さん、

実際には、アイテムが指すアクションを指定するために使用できる Action というメソッドがあります。知性がかなり混乱しているので、おそらくあなたはそれを見ません。次のように、もう少し具体的にすることができます。

.BindTo(Model,(NavigationBindingFactory<TreeViewItem> mappings) =>
    {
        mappings.For<Category>(binding => binding
                .ItemDataBound((item, category) =>
                {
                    item.Action("Test", "Home", new{text=category.CategoryName});//here you can assign the action method , the last parameter is the route values
                    item.Text = category.CategoryName;
                })
     }

これがあなたが探しているものであることを願っています。

于 2012-08-06T21:41:11.180 に答える