我根据此IgniteUI教程创建了一个拖放树列表。树列表效果很好,但是问题出在孩子身上。我在孩子中变得不确定,如图所示
这是我的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": []
}
]
我找到了问题,但我仍在寻找解决方法。问题是我仅将父textKey绑定为“ ServiceCounter”,将valueKey绑定为“ ServiceCounterId”。但是孩子有不同的textKey和valueKey。我不知道该怎么做。任何意见将是有益的。谢谢。
最佳答案
子绑定以分层方式定义。在您的示例中,唯一的绑定层是顶层数据层,因此树正在寻找与顶层数据层相同的文本键和值键。定义方法如下:
bindings: {
textKey: 'ServiceCounter',
valueKey: 'ServiceCounterId',
childDataProperty: 'ServicePoints',
bindings: {
textKey: 'ServicePoint',
valueKey: 'ServicePointId'
}
},