1

我想将 {{trade}} 及其父级传递给 open 函数。

当我单击 li 时,我希望父(股票代码)数据和子(交易)数据显示在警报框中。

这是 plunkr:http ://plnkr.co/edit/QuG8NcOvPKVAnfRNYwlx?p=preview

html:

<table ng-controller = "TickerListCtrl">
<thead>
  <th>Symbol</th>
</thead>
<tbody ng-repeat="ticker in tickers">
  <tr ng-click="showTrades(ticker)">
      <td>{{ticker.Ticker}}</td>
  </tr>
  <tr ng-show="ticker.showTrades">
      <td colspan="2">
        <ul ng-repeat="trade in ticker.trades">
          <li ng-click="open(trade)">{{trade}}</li>
        </ul>
      </td>
  </tr>
 </tbody>
</table> 

代码:

  $scope.tickers = [
{
    "Ticker": "4512",
    "TradeCount": "91",
    "trades" :
      [{
        "one": "this one",
        "two": "this two",
        "three": "this three"
      },
      {
        "one": "this one",
        "two": "this two",
        "three": "this three"
      },
      {
        "one": "this one",
        "two": "this two",
        "three": "this three"
      },
      {
        "one": "this one",
        "two": "this two",
        "three": "this three"
      },
      {
        "one": "this one",
        "two": "this two",
        "three": "this three"
      },
      {
        "one": "this one",
        "two": "this two",
        "three": "this three"
      },
      {
        "one": "this one",
        "two": "this two",
        "three": "this three"
      }]
}]
4

1 回答 1

2
$scope.open = function (trade) {
   alert(ticker.Ticker);
};

替换为:

 $scope.open = function (ticker, trade) {
  var myObj = {};
  myObj['Ticker'] = ticker['Ticker'];
  myObj['TradeCount'] = ticker['TradeCount'];
  delete trade['$$hashKey'];
  myObj['trades'] = trade;

 alert(JSON.stringify(myObj));

};

演示

于 2013-09-18T07:05:16.627 回答