0

Do you know how to use dynamic/chained variables inside a controller variable definition?

I have created this plnkr to further outline what I am trying to achieve: http://plnkr.co/edit/xOjhf8b7ZIxVhc1Id3xo

In the NodeCtrl, I am trying to dynamically access a node from a json object and I can't find the correct syntax to write out the chain.

I have tried a number of combinations but haven't found the correct way yet:

  //var jsonChunk = "data." + $scope.transcendType;
    $scope.tabinventory =  data.$scope.transcendType; 
                         //data;
                         //jsonChunk; 
                         //function() { return "data." + $scope.transcendType; };
    alert($tabinventory[0].title)
  //alert($scope.tabinventory.project[0].title);

Any help you could provide would be greatly appreciated.

All the best,

Ben

4

1 回答 1

0

您是否尝试过记录 $scope.transcendType 以确保在该上下文中正确定义它?

假设它已正确定义,请尝试 data[$scope.transcendType]。

于 2013-10-28T16:20:28.360 回答