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 に答える