Ignite UI TreeList 绑定两个名称和值
Ignite UI TreeList binding two names and values
我根据这个 IgniteUI 教程创建了一个拖放树列表。树列表运行良好,但问题出在 child。如图所示,我在 child 中未定义
这是我的 ts 代码:
this.options = {
checkboxMode: 'triState',
singleBranchExpand: true,
dataSource: jQuery.extend(true, [], this.ServiceCounterPointRelations),
dataSourceType: 'json',
initialExpandDepth: 2,
pathSeparator: '.',
bindings: {
textKey: 'ServiceCounter',
valueKey: 'ServiceCounterId',
childDataProperty: 'ServicePoints'
},
dragAndDrop: true,
dragAndDropSettings: {
allowDrop: true,
customDropValidation: function (element) {
var valid = true,
droppableNode = jQuery(this);
if (droppableNode.is('a') && droppableNode.closest('li[data-role=node]').attr('data-value') === 'File') {
valid = false;
}
return valid;
}
}
};
this.ServiceCounterPointRelations包含以下json
"ServiceCounterPointRelations": [
{
"ServiceCounterId": 2,
"ServiceCounter": "Main Counter",
"ServicePoints": [
{
"ServicePointId": 2,
"ServicePoint": "Service Point 1"
}
]
},
{
"ServiceCounterId": 3,
"ServiceCounter": "Counter 1",
"ServicePoints": []
},
{
"ServiceCounterId": 4,
"ServiceCounter": "Test for 2",
"ServicePoints": []
},
{
"ServiceCounterId": 5,
"ServiceCounter": "ASD",
"ServicePoints": [
{
"ServicePointId": 1,
"ServicePoint": "DER"
},
{
"ServicePointId": 3,
"ServicePoint": "ER"
}
]
},
{
"ServiceCounterId": 6,
"ServiceCounter": "ASD",
"ServicePoints": []
},
{
"ServiceCounterId": 7,
"ServiceCounter": "EEE",
"ServicePoints": []
},
{
"ServiceCounterId": 8,
"ServiceCounter": "With New Tog",
"ServicePoints": []
}
]
我发现了问题,但我仍在寻找修复方法。问题是我仅将 parent textKey 绑定为 'ServiceCounter' 并将 valueKey 绑定为 'ServiceCounterId'。但是 child 有不同的 textKey 和 valueKey。我不知道该怎么做。任何意见将是有益的。谢谢。
子绑定以分层方式定义。在您的示例中,唯一的绑定层是顶部数据层,因此树正在寻找与顶部数据层中相同的文本和值键。定义方法如下:
bindings: {
textKey: 'ServiceCounter',
valueKey: 'ServiceCounterId',
childDataProperty: 'ServicePoints',
bindings: {
textKey: 'ServicePoint',
valueKey: 'ServicePointId'
}
},
我根据这个 IgniteUI 教程创建了一个拖放树列表。树列表运行良好,但问题出在 child。如图所示,我在 child 中未定义
这是我的 ts 代码:
this.options = {
checkboxMode: 'triState',
singleBranchExpand: true,
dataSource: jQuery.extend(true, [], this.ServiceCounterPointRelations),
dataSourceType: 'json',
initialExpandDepth: 2,
pathSeparator: '.',
bindings: {
textKey: 'ServiceCounter',
valueKey: 'ServiceCounterId',
childDataProperty: 'ServicePoints'
},
dragAndDrop: true,
dragAndDropSettings: {
allowDrop: true,
customDropValidation: function (element) {
var valid = true,
droppableNode = jQuery(this);
if (droppableNode.is('a') && droppableNode.closest('li[data-role=node]').attr('data-value') === 'File') {
valid = false;
}
return valid;
}
}
};
this.ServiceCounterPointRelations包含以下json
"ServiceCounterPointRelations": [
{
"ServiceCounterId": 2,
"ServiceCounter": "Main Counter",
"ServicePoints": [
{
"ServicePointId": 2,
"ServicePoint": "Service Point 1"
}
]
},
{
"ServiceCounterId": 3,
"ServiceCounter": "Counter 1",
"ServicePoints": []
},
{
"ServiceCounterId": 4,
"ServiceCounter": "Test for 2",
"ServicePoints": []
},
{
"ServiceCounterId": 5,
"ServiceCounter": "ASD",
"ServicePoints": [
{
"ServicePointId": 1,
"ServicePoint": "DER"
},
{
"ServicePointId": 3,
"ServicePoint": "ER"
}
]
},
{
"ServiceCounterId": 6,
"ServiceCounter": "ASD",
"ServicePoints": []
},
{
"ServiceCounterId": 7,
"ServiceCounter": "EEE",
"ServicePoints": []
},
{
"ServiceCounterId": 8,
"ServiceCounter": "With New Tog",
"ServicePoints": []
}
]
我发现了问题,但我仍在寻找修复方法。问题是我仅将 parent textKey 绑定为 'ServiceCounter' 并将 valueKey 绑定为 'ServiceCounterId'。但是 child 有不同的 textKey 和 valueKey。我不知道该怎么做。任何意见将是有益的。谢谢。
子绑定以分层方式定义。在您的示例中,唯一的绑定层是顶部数据层,因此树正在寻找与顶部数据层中相同的文本和值键。定义方法如下:
bindings: {
textKey: 'ServiceCounter',
valueKey: 'ServiceCounterId',
childDataProperty: 'ServicePoints',
bindings: {
textKey: 'ServicePoint',
valueKey: 'ServicePointId'
}
},