角度ng重复传递项以与父数据一起使用
Angular ng-repeat pass item to function with parent data?
我想将 {{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));
};
演示
相关文章:
- Javascript-如何让脚本与Ajax请求的数据一起运行
- 如何将数据标签与数据一起传递,以便在高图中的工具提示中显示
- 如何使用xmlhttprequest将图像和其他数据一起发送
- 在Javascript中,如何区分与实际数据一起保存的对象和作为引用保存的对象
- 如何将 .find() 与我们使用 .get() 的数据一起使用
- 如何将自定义网址与余烬数据一起使用
- 角度ng重复传递项以与父数据一起使用
- 使d3力布局与标记数据一起工作
- 如何将角度图与json数据一起使用
- 如何使用Ajax将javascript数组与其他非数组数据一起发送到PHP脚本
- 将函数与附加数据一起传递给sails.js
- 通过post与其他数据一起传递json对象
- 如何将文件与其他数据一起发送到webmethod ?不使用任何插头
- 访问与Redux状态数据一起发送给组件的props
- 文件输入数据未与Dropzone表单的POST数据一起传输
- 在MV*设计模式中,模型是单个数据单元还是与数据一起工作的所有逻辑
- 将Meteor中的list.js与从服务器发布到客户端的数据一起使用
- 如何使用xmlhttprequest使一个新的子节点与php脚本中的节点数据一起出现在html中
- 显示数据和单选按钮,并将单选按钮的选定值与数据一起保存
- 以前的表单数据与当前数据一起发布