我有几个表行,并且在相应行的最后一列中有两个可以执行的操作。
<div class="embedded-list-table-wrapper embedded-medium migration-status-list-container">
<table class="list-table embedded-list-table no-truncate-td">
<thead>
<tr>
<th>
<a href="#list-table" class="table-sort table-sort-desc">
<span class="table-sort-text">Account Name</span>
<span class="table-sort-indicator"></span>
</a>
</th>
<th>
<a href="#list-table" class="table-sort table-sort-desc">
<span class="table-sort-text"># Batches Completed</span>
</a>
</th>
<th style="width:123px;">Actions</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in vm.items | limitTo : vm.pageSize : (vm.currentPage-1)*vm.pageSize">
<td class="table-link"><a class="ng-binding" href="" target="_blank" ng-click="vm.setTenantId($event)">{{item.accountName}}</a></td>
<td class="table-text ng-binding">{{item.completedBatches}}</td>
<td class="table-input">
<div class="btn-group">
<div class="dropdown">
<div class="cog dropdown-toggle" ng-click="batch.showSettings = !batch.showSettings"></div>
<ul class="dropdown-menu visible" ng-show="batch.showSettings">
<li><span class="dropdown-category">Manage</span></li>
<li class=""><a href="" ng-click="vm.removeAccount(item.accountName)">Remove from Panel</a></li>
<li class=""><a href="#" ng-click="vm.setEncoreLink()">View</a></li>
</ul>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
现在,此<a>" in View
按钮会将我重定向到类似https://encore.rackspace.com/accounts/<tenant-id>
的网址。 <tenant-id>
将来自第一列Account Name
值,我们可以将其拆分为:
vm.setEncoreLink = function($event){
debugger;
var tenant_id_text = $event.currentTarget.text;
var tenant_id = tenant_id_text.substring(tenant_id_text.lastIndexOf("#")+1,tenant_id_text.lastIndexOf(")"));
var encoreUrl = "https://encore.rackspace.com/accounts/"+tenant_id;
$window.location.href=encoreUrl;
}
如果$ event从第一列值传递。 如何访问并传递,以便可以访问tenant_id? 或者还有其他出路吗?
答案 0 :(得分:2)
好的,所以在我看来,你试图从中得到的文字实际上是'{{item.accountName}}',对吗?另外你实际上并不明确,但是从你的示例代码我假设你正在尝试setEncoreLink
函数。
所以你可以这样做:
<li class=""><a href="#" ng-click="vm.setEncoreLink(item)">View</a></li>
然后你的功能可以
vm.setEncoreLink = function(item){
debugger;
var tenant_id_text = item.accountName;
var tenant_id = tenant_id_text.substring(tenant_id_text.lastIndexOf("#")+1,tenant_id_text.lastIndexOf(")"));
var encoreUrl = "https://encore.rackspace.com/accounts/"+tenant_id;
$window.location.href=encoreUrl;
}