c# - Kendo Treeview 和阅读网址

标签 c# asp.net-mvc-4 kendo-treeview

问题:
使用 HierarchicalDataSource 将 Kendo Treeview 绑定(bind)到远程数据源时遇到问题

Object Doesn't support property or method 'level'



我认为问题与我的 json 响应有关,因为它是用一大堆转义字符编码的;我不知道如何强制 Transport.Read.Url 使用 $.parseJson(data)。我所能做的就是将 url 提供给我在 Controller 中的操作;但我的 Controller 的结果是纯 json,有很多转义字符......请帮忙

Controller :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;

[HttpPost]
public JsonResult TreeItems(int? jobId, int? parentJobId)
{
    var data = new List<object>()
    {
        new
        {
            NodeId = 1,
            caption = "test1",
            hasChildren = true,
            items = new List<object>()
            {
                new
                {
                    NodeId = 2,
                    caption = "test2",
                    hasChildren = false,
                    parentId = "1"
                },
                new
                {
                    NodeId = 3,
                    caption = "test3",
                    hasChildren = false,
                    parentId = "1"
                },
            }
        }
    };
    return Json(JsonConvert.SerializeObject(data), JsonRequestBehavior.AllowGet);
}

JavaScript:
var ds1 = new kendo.data.HierarchicalDataSource(
{
    transport:
    {
        read:
        {
            url: urlToTreeItems
            , dataType: "json"
            , type: "POST"
        },
        schema:
        {
            model:
            {
                id: "id",
                text: "caption",
                hasChildren: "hasChildren"
            }
        },
    }
});
var tv = $("#test").kendoTreeView(
{
    dataSource: ds1
}).data("kendoTreeView");

回复:
"[{\"NodeId\":1,\"caption\":\"test1\",\"hasChildren\":true,\"items\":[{\"NodeId\":2,\"caption\":\"test2\",\"hasChildren\":false,\"parentId\":\"1\"},{\"NodeId\":3,\"caption\":\"test3\",\"hasChildren\":false,\"parentId\":\"1\"}]}]"

//EDITED:还想提一下我尝试了以下方法;它只是为节点文本显示“未定义”,并且树节点不展开
var ds2 = new kendo.data.HierarchicalDataSource(
{
    transport:
    {
        read: function (options)
        {
            Ajax(urlToTreeItems, false, null, "POST", null, "application/json; charset=utf-8", "json",
            function (result)
            {
                var jResult = $.parseJSON(result);
                options.success(jResult);
            });
        },
        schema:
        {
            model:
            {
                id: "NodeId",
                text: "caption",
                hasChildren: "hasChildren"
            }
        },
    }
});

var tv = $("#test").kendoTreeView(
{
    dataSource: ds2
}).data("kendoTreeView");

最佳答案

尝试 :

 schema:
    {
        model:
        {
            id: "NodeId",
            children: "items"
            hasChildren: "hasChildren"
        }
    }

关于c# - Kendo Treeview 和阅读网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26557746/

相关文章:

entity-framework - 使用代码优先迁移与 Entity Framework 和 SQL Server 时如何创建聚集索引

javascript - 从kendo UI DataSource获取原始数据

c# - 当 c# 中的扬声器没有声音时,如何使用 WasapiLoopbackCapture 录制音频?

c# - NPoco InsertBulk() 花了 45 *分钟* 插入 20,000 条记录

asp.net - SSO 表单例份验证问题。无法解密身份验证 cookie

jquery - Kendo Treeview 节点编辑/更新

asp.net-mvc-4 - Kendo MVC treeview 将选定的节点传递给网格

C# 堆栈溢出异常

c# - 我应该在 MVVM 的模型中使用 ObservableCollections 吗?

asp.net-mvc-4 - Identityserver3 - HybridFlow 不返回配置文件范围