1

我基于这个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。我不知道该怎么做。任何意见将是有益的。谢谢。

4

1 回答 1

1

子绑定以分层方式定义。在您的示例中,唯一的绑定层是顶层数据层,因此树正在寻找与顶层数据层相同的文本和值键。以下是如何定义它:

bindings: {
    textKey: 'ServiceCounter',
    valueKey: 'ServiceCounterId',
    childDataProperty: 'ServicePoints',
    bindings: {
        textKey: 'ServicePoint',
        valueKey: 'ServicePointId'
    }
},
于 2016-12-05T09:19:07.663 回答