我有一些表行,并且在各行的最后一列中,可以执行两个操作。

        <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?
还是还有其他出路?

最佳答案

好的,在我看来,您想要从中获得的文字实际上是'{{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;
            }

10-06 00:18