使用 ng 选中的值添加到链接
Using the ng-checked value to add to a link
解释起来很复杂,但我会尽力而为。我想要实现的是,使用复选框值(这是我的 ID)并选中其中一个(有很多,因为它们是列表中的项目)时,我想使用该值并能够触发我的锚标签来编辑该项目。
复选框本身
<td><input type="checkbox" value="item.iid" ng-checked="item.iid" id="item_{{item.iid}}"></td>
编辑链接
<a href="#/edit/{{item.iid}}"><div class="edit">Edit</div></a>
我的编辑控制器
var EditCtrl = function ($scope, $location, $routeParams, Item) {
$scope.action = "Update";
var id = $routeParams.editId;
$scope.item = Item.get({ id: id });
$scope.save = function () {
Item.update({ id: id }, $scope.item, function () {
$location.path('/');
});
};
};
您应该
使用 ng-click 而不是 ng-checked,当用户单击时,您应该将当前项目标记为选中或未选中下面的示例
<a href="#/edit/{{lastChecked}}"><div class="edit">Edit</div></a>
<td><input type="checkbox" value="item.iid" ng-checked="amIChecked(item.iid)" ng-click="checkMe(item.iid)" id="item_{{item.iid}}"></td>
这是 js
var EditCtrl = function ($scope, $location, $routeParams, Item) {
$scope.action = "Update";
var id = $routeParams.editId;
$scope.lastChecked = null;
$scope.item = Item.get({ id: id });
$scope.checkMe = function(id){
if($scope.lastChecked=== id){
$scope.lastChecked= null;
}else{
$scope.lastChecked= id;
}
};
$scope.amIChecked = function(id){
return $scope.lastChecked=== id;
};
$scope.save = function () {
Item.update({ id: id }, $scope.item, function () {
$location.path('/');
});
};
};
相关文章:
- 如何在Angular中的表的所有单元格中添加链接
- 如何使用 HTML/JavaScript 为对象添加链接
- 如何在滑块图像上添加链接
- HTML::向输入标记添加链接
- 正在向库图像添加链接
- 在旋转javascript横幅中添加链接
- 向每个堆叠条形图项目添加链接
- 根据课程自定义字段在课程页面上添加链接
- 如何使用java脚本添加链接
- 如何在D3元素中添加链接
- 如果满足条件,则使用JQuery向元素添加链接
- 当屏幕尺寸较小时,可使用Javascript向移动菜单添加链接.不再有效
- javascript下拉列表-无法添加链接
- Ext JS Gannt 在任务之间添加链接
- 添加链接时 JQuery 停止工作
- Javascript 在添加表行时添加链接文本
- 如何在 d3.js 行添加链接名称
- Umbraco 将从第 @nodename 页添加链接作为表单上的文本输入值
- 在jQuery插件中添加链接的方法
- 在可折叠内容标头(拆分链接)中添加链接 - 缺少 css