如何更改 ng

编程入门 行业动态 更新时间:2024-10-06 10:36:33
本文介绍了如何更改 ng-repeat 中单个元素的 ng-click 行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在重构一个用 angular 编写的表格.当前 ng-repeat 用于创建多个表行,其中任何一个在单击时都将重定向到给定的 ui-sref:

I am refactoring a table written in angular. Currently ng-repeat is used to create multiple tables rows, any of which will redirect to a given ui-sref when clicked upon:

        <tbody>
            <tr ng-repeat="user in group | orderBy:sorter:reverse" class="tablebox-content" ui-sref="admin.candidates.detail({_id: user._id})">
                <td class="name">{{user.name}}</td>
                <td>{{user.attending ? 'Yes' : 'No'}}</td>
                <td class="interestDeclared">{{user.interestDeclared}}</td>
                <td class="interestThreeOrGreater">{{user.interestThreeOrGreater}}</td>
                <td class="github"><a ng-href="{{user.github}}"a>{{user.github}}</a></td>
                <td class="email"><a ng-href="mailto:{{user.email}}">{{user.email}}</a></td>
                <td class="location">{{user.city}}</td>
                <td class="stage">{{user.searchStage === 'Out' ? 'Opted Out' : user.searchStage}}</td>
            </tr>
        </tbody>

我需要用复选框替换当前显示是"或否"的第二个 td,问题是单击复选框时需要切换复选框,而不是像其他人一样重定向到 ui-sreftd 的.

I need to replace the 2nd td, currently displaying 'Yes' or 'No' with a checkbox, the problem being that the check box needs to be toggled when clicked on, and not redirect to the ui-sref like the rest of the td's.

我有一个可行的解决方案,就是将 ui-sref 硬编码到除复选框之外的每一个中:

I have a working solution which is to hardcode the ui-sref into every except for the checkbox:

        <tbody>
            <tr ng-repeat="user in group | orderBy:sorter:reverse" class="tablebox-content">
                <td ui-sref="admin.candidates.detail({_id: user._id})" class="name">{{user.name}}</td>
                <td><input type="checkbox" ng-model="user.attending"></td>
                <td ui-sref="admin.candidates.detail({_id: user._id})" class="interestDeclared">{{user.interestDeclared}}</td>
                <td ui-sref="admin.candidates.detail({_id: user._id})" class="interestThreeOrGreater">{{user.interestThreeOrGreater}}</td>
                <td ui-sref="admin.candidates.detail({_id: user._id})" class="github"><a ng-href="{{user.github}}"a>{{user.github}}</a></td>
                <td ui-sref="admin.candidates.detail({_id: user._id})" class="email"><a ng-href="mailto:{{user.email}}">{{user.email}}</a></td>
                <td ui-sref="admin.candidates.detail({_id: user._id})" class="location">{{user.city}}</td>
                <td ui-sref="admin.candidates.detail({_id: user._id})" class="stage">{{user.searchStage === 'Out' ? 'Opted Out' : user.searchStage}}</td>
            </tr>
        </tbody>

是否有另一种更优雅和/或 Angular 的方式来实现此解决方案?

Is there another, more elegant and/or Angular way to implement this solution?

推荐答案

你可以简单地这样做:

    <tbody>
        <tr ng-repeat="user in group | orderBy:sorter:reverse" class="tablebox-content" ui-sref="admin.candidates.detail({_id: user._id})">
            <td class="name">{{user.name}}</td>
            <td ng-click="$event.stopPropagation()"><input type="checkbox" ng-model="user.attending"></td>
            <td class="interestDeclared">{{user.interestDeclared}}</td>
            <td class="interestThreeOrGreater">{{user.interestThreeOrGreater}}</td>
            <td class="github"><a ng-href="{{user.github}}"a>{{user.github}}</a></td>
            <td class="email"><a ng-href="mailto:{{user.email}}">{{user.email}}</a></td>
            <td class="location">{{user.city}}</td>
            <td class="stage">{{user.searchStage === 'Out' ? 'Opted Out' : user.searchStage}}</td>
        </tr>
    </tbody>

这篇关于如何更改 ng-repeat 中单个元素的 ng-click 行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-21 17:56:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1007897.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何更改   ng

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!