使用angularjs

时间:2016-12-10 10:56:21

标签: angularjs html5

我在桌子上有一棵树。我想知道如何使用angularjs将拖放功能添加到下面的树。任何帮助将非常感激。 Plunkr添加了click here

// html文件

<html>
<head>
<script src="angular.min.js"></script>

<script src="script.js"></script>
<link rel="stylesheet" href="style.css"/>
<link rel="stylesheet" href="bootstrap.min.css" />
</head>
<body>
<h1>
  Tree Table and Checkbox with AngularJS
</h1>
<hr>
<div class="wrapper" data-ng-app="testApp" data-ng-controller="treeTable">
  <table class="table-nested">
    <thead>
      <tr>
        <!-- <th >
          <input data-ng-checked="(list | selected).length == list.length" data-ng-click="toggleAllCheckboxes($event)" type="checkbox" />
        </th> -->
        <th>
         <input data-ng-checked="(list | selected).length == list.length" data-ng-click="toggleAllCheckboxes($event)" type="checkbox" /> Name
        </th>
        <th class="cell-members">
          Version
        </th>
        <th>
          Size
        </th>
      </tr>
    </thead>
    <tbody class="newRepo" style="font-size:12px" data-ng-class="{opened: item.opened}" data-ng-include="&#39;table_tree.html&#39;" data-ng-repeat="item in list"></tbody>
  </table>
  <script id="table_tree.html" type="text/ng-template">
    <tr ng-class="{parent: item.children}" ng-init="parentScope = $parent.$parent; initCheckbox(item, parentScope.item)">

      <td class="cell-name" ng-if="level &amp;&amp; level &gt; 1">
      <span style="padding-left: 30px" >&nbsp;  <input ng-change="toggleCheckbox(item, parentScope)" ng-model="item.selected" type="checkbox" />
        {{item.name}} </span>
      </td>
<td class="cell-name top-border" ng-if=" &#40;&#33;level &amp;&amp; level &lt;&#61; 1 &#41; &#124;&#124 &#40;level &amp;&amp; level &lt;&#61; 1&#41;">
        <span style="padding-left:11px" ng-click="item.opened = !item.opened"></span>&nbsp;<input ng-change="toggleCheckbox(item, parentScope)" ng-model="item.selected" type="checkbox" />
        {{item.name}}
      </td>

<td class="cell-name top-border" ng-if="&#33;level">
       <span class="indent" ng-click="item.opened = !item.opened"></span>&nbsp;<input ng-change="toggleCheckbox(item, parentScope)" ng-model="item.selected" type="checkbox" />
        {{item.name}}
      </td>

      <td class="cell-members top-border">
        {{item.Version}} 
      </td>
      <td>
        {{item.Size}}
      </td>
    </tr>
    <tr class="children" ng-if="item.children &amp;&amp; item.children.length &gt; 0">
      <td colspan="3">
        <table>
          <tbody style="font-size:12px" ng-class="{opened: item.opened}" ng-include="&#39;table_tree.html&#39;" ng-init="level = level + 1" ng-repeat="item in item.children"></tbody>
        </table>
      </td>
    </tr>
  </script>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

查看此指令,在尝试了其中几个之后,我发现这个指令非常灵活,我已经在我的一个项目中成功使用了它:

Angular Drag and Drop