【问题标题】:Why this Kendo UI Treelist - angular version - does not work?为什么这个 Kendo UI Treelist - angular version - 不起作用?
【发布时间】:2015-11-24 21:37:39
【问题描述】:

我有一个来自 WebApi 的数据源 - 请在 JSON 字符串下方找到 - 我想在 Kendo UI Treelist 中显示它。我使用的是 Angular 版本。

我一直试图弄清楚为什么它对我不起作用几个小时。 TreeList 总是说“请求失败”。有些东西我还看不到。控制台没有错误,因为我使用的是缩小版,所以无法调试。

另一方面,我有几个问题:

  • 我是否正确理解架构中的 IdParentId 属性描述了记录之间的父子关系?
  • 如果是这样,那么我要移交 TreeList 的数据应该是一个普通对象列表,其中: 每个项目都应该包含一个 Id ParentId 数据,或者可以按照示例中的描述进行映射的等效项。

来自 WebApi 的 JSON

[{
    "Id": 10,
    "Name": "tiz",
    "ParentId": null
},
{
    "Id": 20,
    "Name": "husz",
    "ParentId": null
},
{
    "Id": 30,
    "Name": "harm",
    "ParentId": 10
},
{
    "Id": 40,
    "Name": "negyv",
    "ParentId": 20
}]

角度代码

    function activate() {

        vm.treeOptions = {
            dataSource: {
                transport: {
                    read: {
                        url: configurationService.goNoGoWebApiRootUrl + 'WorkItemClassificationNode/Get2/Depth',
                        dataType: "jsonp"
                    },
                    parameterMap: function (options, operation) {
                        if (operation !== "read" && options.models) {
                            return { models: kendo.stringify(options.models) };
                        }
                    }
                },
                schema: {
                    model: {
                        id: "Id",
                        parentId: "ParentId",
                        fields: {
                            Id: { type: "number", editable: false, nullable: true },
                            ParentId: { type: "number", editable: false, nullable: true },
                            Name: { type: "string", editable: false, nullable: true }
                        }
                    }
                }
            },
            sortable: false,
            editable: false,
            columns: [
                {field: "Id", title: "Id", width: "150px"},
                {field: "Name", title: "Name", width: "500px"},
                {field: "ParentId", title: "ParentId", width: "100px"}
            ]
        }

    }

【问题讨论】:

    标签: angularjs kendo-ui kendo-treelist


    【解决方案1】:

    经过 1-2 小时的调查,发现 datatype 参数 - 上面示例中的“jsonp” - 不正确,因为我的服务返回 json “应用程序/json”。

    调查需要安装kendo-ui-demos-service 项目以了解其工作原理。它返回“application/x-javascript”数据类型。

    【讨论】:

      猜你喜欢
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 2020-09-22
      • 2017-01-31
      • 1970-01-01
      • 2015-01-17
      • 2016-01-13
      • 1970-01-01
      相关资源
      最近更新 更多