简体   繁体   English

与Angular ngRepeat的树桌

[英]Tree Table With Angular ngRepeat

We need to display some tabular data according to a hierarchy. 我们需要根据层次结构显示一些表格数据。 For example a list of country with their population and the area they cover, along with some of their cities. 例如,包含人口和所覆盖区域的国家列表,以及他们的一些城市。 It could go to deeper levels as well such as neiborhood, etc. 它可以进入更深层次,如neiborhood等。

Place        Population    Area
---------------------------------
Canada      33,500,000     10,000,000
  Toronto    2,600,000         612
  Montreal   1,300,000         300
USA         317,000,000     9,800,000
  ...          ...             ...
  ...          ...             ...
     ...       ...             ...           
     ...       ...             ... 

I've tried to used Angular and ngRepeat to create a Tree table to display this hierarchy but it doesn't work. 我试图使用Angular和ngRepeat创建一个Tree表来显示这个层次结构,但它不起作用。 I also tried this nice solution from Brendan Owen http://jsfiddle.net/brendanowen/uXbn6/8/ that uses ul and li tags but it doesn't work either when table and tr/td tags are used. 我也尝试过使用ul和li标签的Brendan Owen http://jsfiddle.net/brendanowen/uXbn6/8/这个很好的解决方案,但是当使用table和tr / td标签时它也不起作用。 Is it possible to accomplish this for a table? 是否可以为表格完成此操作?

Whilst it doesn't use a HTML table, have you checked out the angular dynamic-tree ? 虽然它不使用HTML表格,你有没有检查出角度动态树

It may also be worth checking out the blog post which spawned it , since there is a little less code to digest there. 它也可能值得查看产生它的博客文章,因为那里消化的代码少了一点。

If you are looking for an example, here is a jsFiddle . 如果您正在寻找一个例子,这里有一个jsFiddle Where your html would simply become something like: 你的html会变成这样的东西:

<ui-tree
    ng-model="assets"
    load-fn="loadChildren"
    expand-to="hierarchy"
    selected-id="111"
    attr-node-id="assetId" />

This project offers good Angular tree with a good following (435+ starred). 这个项目提供了良好的Angular树和良好的追随者(435+星级)。

https://github.com/nickperkinslondon/angular-bootstrap-nav-tree https://github.com/nickperkinslondon/angular-bootstrap-nav-tree

A sample of the tree can be found here. 可以在这里找到树的样本。 http://nickperkinslondon.github.io/angular-bootstrap-nav-tree/test/bs3_ng120_test_page.html http://nickperkinslondon.github.io/angular-bootstrap-nav-tree/test/bs3_ng120_test_page.html

For non-Angular option, jquery treetable does offer a fairly easy implementation. 对于非Angular选项,jquery treetable确实提供了相当简单的实现。

http://ludo.cubicphuse.nl/jquery-treetable/ http://ludo.cubicphuse.nl/jquery-treetable/

Each node (parent, child or subsequent children) needs to be a tr element in table, needing to specify id of its own and of the parent node. 每个节点(父节点,子节点或后续子节点)都需要是表中的tr元素,需要指定其自身和父节点的id。

<table>
    <tr data-tt-id="1">
        <td>Parent</td>
    </tr>
    <tr data-tt-id="2" data-tt-parent-id="1">
        <td>Child</td>
    </tr>
</table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM