gpt4 book ai didi

javascript - Angular ng-repeat 传递项目以与父数据一起运行?

转载 作者:行者123 更新时间:2023-11-30 17:51:45 24 4
gpt4 key购买 nike

我想将 {{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"
}]
}]

最佳答案

$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));

};

DEMO

关于javascript - Angular ng-repeat 传递项目以与父数据一起运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18865445/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com