在我的第一角應用程序我有這樣的數據:AngularJS:由字段名稱得到數組值
tree_rows = [{"level":1,"branch":{"Name":"USA","Area":9826675,"Population":318212000,"TimeZone":"UTC -5 to -10","children":[{"Name":"California","Area":423970,"Population":38340000,"TimeZone":"Pacific Time","children":[{"Name":"San Francisco","Area":231,"Population":837442,"TimeZone":"PST"},{"Name":"Los Angeles","Area":503,"Population":3904657,"TimeZone":"PST"}]},{"Name":"Illinois","Area":57914,"Population":12882135,"TimeZone":"Central Time Zone","children":[{"Name":"Chicago","Area":234,"Population":2695598,"TimeZone":"CST"}]}],"level":1,"expanded":true,"uid":"0.5810681234579533","Options":[]},"label":"USA","tree_icon":"icon-file glyphicon glyphicon-file fa fa-file","visible":true},{"level":1,"branch":{"Name":"Texas","Area":268581,"Population":26448193,"TimeZone":"Mountain","level":1,"expanded":true,"uid":"0.8260199765209109","Options":[]},"label":"Texas","tree_icon":"icon-file glyphicon glyphicon-file fa fa-file","visible":true}]
colDefinitions = [{"field":"Area"},{"field":"Population"},{"field":"TimeZone"},{"field":"children"}]
和我嘗試經由表網格視圖中查看:
<tr ng-repeat=\"row in tree_rows | filter:{visible:true} track by row.branch.uid\"
ng-class=\"'level-' + {{ row.level }} + (row.branch.selected ? ' active':'')\" class=\"tree-grid-row\">
<td class=\"text-primary\"><a ng-click=\"user_clicks_branch(row.branch)\"><i ng-class=\"row.tree_icon\"
ng-click=\"row.branch.expanded = !row.branch.expanded\"
class=\"indented tree-icon\"></i>
</a><span class=\"indented tree-label\" ng-click=\"user_clicks_branch(row.branch)\">
{{row.branch[expandingProperty]}}</span>
</td>
<td ng-repeat=\"col in colDefinitions\">{{row.branch[col.field]}}</td> - this line!!!
</tr>
和所有是好的,只是我想顯示不是所有的數據爲:<td ng-repeat=\"col in colDefinitions\">{{row.branch[col.field]}}</td>
但例如{{row.branch[Name]}} , {{row.branch[Population]}}
並且我沒有看到任何數據。但爲什麼?
如何通過字段從我的數組中獲取數據?
PS:我用這個:https://github.com/khan4019/tree-grid-directive/blob/master/README.md
請粘貼代碼http://plnkr.co/ – sagar43
很難猜測,因爲它可能是很多事情,直到你在任何地方分享你的代碼。首先,我不會推薦這個樹指令作爲第一件事來嘗試角度。有大量的初學者教程可以在線獲取。但是,如果您想嘗試此樹指令,請轉至此演示鏈接:http://khan4019.github.io/tree-grid-directive/test/treeGrid.html獲取treeGridTest.js和treeGrid.html以及其他庫和玩它...然後將您的數據在代碼中,並從那裏... – KhanSharp
@KhanSharp我的代碼是這個指令...所有這一切都基於您的鏈接 – brabertaser19