I want to pass the {{trade}} with its parent to the open function.
我想将{{trade}}及其父级传递给open函数。
when i click the li I want the parent(ticker) data and the child(trade) data displayed in an alert box.
当我点击li时,我希望父级(自动收报机)数据和子级(交易)数据显示在警告框中。
here is the plunkr: http://plnkr.co/edit/QuG8NcOvPKVAnfRNYwlx?p=preview
这里是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>
tickers:
$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"
}]
}]
1 个解决方案
#1
2
$scope.open = function (trade) {
alert(ticker.Ticker);
};
Replace To :
替换为:
$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));
};
#1
2
$scope.open = function (trade) {
alert(ticker.Ticker);
};
Replace To :
替换为:
$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));
};