为什么这个 Kendo UI Treelist - angular 版本 - 不起作用?
Why this Kendo UI Treelist - angular version - does not work?
我有一个来自 WebApi 的数据源 - 请在 JSON 字符串下方找到 - 我想在 Kendo UI Treelist 中显示它。我正在使用 Angular 版本。
我一直在尝试弄清楚为什么它几个小时都不适合我。 TreeList 总是说 "Request failed"。有些东西我还看不到。控制台没有报错,我用的是缩小版,无法调试
另一方面,我有几个问题:
- 我是否正确理解架构中的 Id、ParentId 属性描述了记录之间的父子关系?
- 如果是这样,那么我想移交 TreeList 的数据应该是一个普通对象列表,其中:每个项目都应该包含一个 Id ParentId 数据,或者可以映射的等效项,如例如。
Json 来自 WebApi:
[{
"Id": 10,
"Name": "tiz",
"ParentId": null
},
{
"Id": 20,
"Name": "husz",
"ParentId": null
},
{
"Id": 30,
"Name": "harm",
"ParentId": 10
},
{
"Id": 40,
"Name": "negyv",
"ParentId": 20
}]
Angular代码:
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"}
]
}
}
经过 1-2 小时的调查后发现 datatype 参数 - "jsonp" 在上面的示例 - 不正确,因为我的服务 returns json "application/json".
调查需要安装 kendo-ui-demos-service 项目以查看其工作原理。它 returns "application/x-javascript" 数据类型。
我有一个来自 WebApi 的数据源 - 请在 JSON 字符串下方找到 - 我想在 Kendo UI Treelist 中显示它。我正在使用 Angular 版本。
我一直在尝试弄清楚为什么它几个小时都不适合我。 TreeList 总是说 "Request failed"。有些东西我还看不到。控制台没有报错,我用的是缩小版,无法调试
另一方面,我有几个问题:
- 我是否正确理解架构中的 Id、ParentId 属性描述了记录之间的父子关系?
- 如果是这样,那么我想移交 TreeList 的数据应该是一个普通对象列表,其中:每个项目都应该包含一个 Id ParentId 数据,或者可以映射的等效项,如例如。
Json 来自 WebApi:
[{
"Id": 10,
"Name": "tiz",
"ParentId": null
},
{
"Id": 20,
"Name": "husz",
"ParentId": null
},
{
"Id": 30,
"Name": "harm",
"ParentId": 10
},
{
"Id": 40,
"Name": "negyv",
"ParentId": 20
}]
Angular代码:
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"}
]
}
}
经过 1-2 小时的调查后发现 datatype 参数 - "jsonp" 在上面的示例 - 不正确,因为我的服务 returns json "application/json".
调查需要安装 kendo-ui-demos-service 项目以查看其工作原理。它 returns "application/x-javascript" 数据类型。