且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

创建正深层次使用AngularJS一个无序列表

更新时间:2022-12-09 07:55:18

在情况下,任何人有兴趣最省力的方式来做到这一点,而无需创建一个指令(不是说你不应该,但只是提供一个变化),这里是一个简单的例子:

In case anyone is interested in the "least-effort" way to do this without creating a directive (not that you shouldn't, but just offering a variation), here is a simple example:

http://jsbin.com/hokupe/1/edit

另外这里有一个博客帖子和它是如何工作10-15分钟的视频:

Also here's a blog post and a 10-15 minutes video on how it works:

http://gurustop.net/blog/2014/07/15/angularjs-using-templates-ng-include-create-infinite-tree/

样code:

  <script type="text/ng-template" id="treeLevel.html">
    <ul>
      <li ng-repeat="item in items">
        <input type="checkbox"
          name="itemSelection"
          ng-model="item._Selected" />
        {{item.text}}
        <div ng-include=" 'treeLevel.html'"
            onload="items = item.children">
        </div>
      </li>
    </ul>
  </script>
  <div ng-include=" 'treeLevel.html' "
       onload="items = sourceItems">
  </div>