angularjs - AngularJS 我懒得正确缩进或写一个好标题
问题描述
单击戴尔按钮时,ID 已正确传递给 del-function,但 del-function 无法将 id 发送到 del.php 页面。
<div ng-controller="thecontroller">
<table class="table">
<head>
<th>Name</th>
<th>E-mail</th>
<th>Passward</th>
</head>
<tbody ng-repeat="x in list">
<td>{{x.name}}</td>
<td>{{x.email}}</td>
<td>{{x.passward}}</td>
<td>
<button ng-click="" class="glyphicon glyphicon-plus"></button>
<button ng-click="del(x.id)" class="glyphicon glyphicon-remove"></button>
</td>
</tbody>
</table>
</div>
var app=angular.module('myapp',[]);
app.controller('thecontroller',function($scope,$http){
$http.get("show.php")
.then(
function(response){
$scope.list=response.data;
});
自爆功能无法发送 id.undefine index id 错误发生
$scope.del=function(value){
console.log(value);
$http.post('del.php',{"id":value}
)
}
});
解决方案
请确保id
对象列表中存在属性,请参考下面的示例,其中我使用了场景的模型并且del
函数正在接收id
.
var app = angular.module('myApp', []);
app.controller('thecontroller', function($scope, $http, $timeout) {
var data = [{
id:1,
name: "one",
email: "one@one.com",
password: "1234"
}, {
id:2,
name: "two",
email: "two@two.com",
password: "1234"
}, {
id:3,
name: "three",
email: "three@three.com",
password: "1234"
}, ]
$timeout(function() {
$scope.names = data;
}, 3000);
/*$http.get("show.php")
.then(function(response) {
$scope.names = response.data;
console.log(response)
});*/
$scope.del=function(value){
console.log(value);
}
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="thecontroller">
<form>
<table>
<tbody>
<tr ng-repeat="x in names">
<td>{{x.name}}</td>
<td>{{x.email}}</td>
<td>{{x.password}}</td>
<td>
<button ng-click="" class="glyphicon glyphicon-plus"></button>
<button ng-click="del(x.id)" class="glyphicon glyphicon-remove"></button>
</td>
</tr>
</tbody>
</table>
</form>
</div>
</body>
</html>
推荐阅读
- python - 如何为将字符串错误显示为参数的查询制作重试装饰器
- javascript - 接受除表情符号外的外来字符的正则表达式
- python - 使用python获取包含正则表达式特定字符的两个变量字符串之间的字符串
- sql - 仅在联合中整理“sql_latin”和“latin1”不匹配冲突 - 如何解决?
- javascript - 更新反应函数内部的状态变量
- javascript - jQuery - 多个按钮点击
- javascript - 基于 Chromium 的浏览器中的奇怪 JavaScript 错误
- testing - 测试人员的虚拟环境来测试我的本地更改?
- python - 如何将类 __init__ 属性作为函数参数传递
- css - HTML/CSS 如何在指定宽度的同时保持右手 div 响应