- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先让我说这不是一个重复的问题,我阅读了每个相关问题!我的编辑功能工作正常,更新数组的推送功能也工作正常,但我确定我从未碰过它,它只是停止工作了!
我要说我的 HTML 表单有 ng-model,没有拼写错误,用于帮助推送。 Angular 代码:
$scope.add = function(id){
$scope.people.push({
name: $scope.name,
phone1: $scope.phone1,
phone2: $scope.phone2,
phone3: $scope.phone3,
email: $scope.email,
city: $scope.city,
state: $scope.state
});
//More code here that resets the forms input//
}
我的编辑功能有效,我的删除功能有效,只有这个,当我点击启动 add() 功能的按钮时,它会重置表单输入,但会将一个空白数组推送到我的 ng-repeat 列表中!
我有一个具有多个输入的表单,其中 ng-model 设置为任意值; name, phone1 ... 等等,而且 Angular 代码是正确的,那为什么这行不通呢?
<div class="centered" ng-show="addcont">
<form id="adder" name="commentForm" method="post">
<h2 class="formtitle">Add Contact</h2>
<table cellpadding="5" cellspacing="5">
<tr>
<td>Name</td>
<td>
<input class="edit" type="text" ng-model="name">
</td>
</tr>
<tr>
<td>Email</td>
<td>
<input class="edit" type="text" ng-model="email">
</td>
</tr>
<tr>
<td>Phone</td>
<td>
<input type="text" id="number" class="edit" maxlength="3" size="3" ng-model="phone1">
<input type="text" id="number" class="edit" maxlength="3" size="3" ng-model="phone2" /> -
<input type="text" id="number" class="edit" maxlength="4" size="5" ng-model="phone3" />
</td>
</tr>
<tr>
<td>City</td>
<td>
<input class="edit" type="text" ng-model="city">
</td>
</tr>
<tr>
<td>State</td>
<td>
<input class="edit" type="text" ng-model="state">
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="button" value="Save" ng-click="add(); `showAdd()">
</td>
</tr>
</table>
</form>
</div>
重大更新!
我用的是JQuery的autotab函数,一注释掉,数组又正常传入了。
该函数用于上面提供的表单,并自动跳转到下一个输入。
函数如下:
<script>
$(document).ready(function(){
$('.edit').autotab();
});
</script>
最佳答案
每次都使用 Jquery 和 angular 并不合适
因此,我们应该使用 Angular 版本的自动选项卡。
因此,这是使用 Angular 自动标签解决的示例。
要添加的重要行是
$.autotab.selectFilterByClass = true;
$.autotab.selectFilterByClass = true;
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
//$('.edit').autotab();
$.autotab.refresh();
$scope.people = [];
$scope.add = function(id){
$scope.people.push({
name: $scope.name,
phone1: $scope.phone1,
phone2: $scope.phone2,
phone3: $scope.phone3,
email: $scope.email,
city: $scope.city,
state: $scope.state
});
setTimeout(function () {
$.autotab.refresh();
}, 1);
//More code here that resets the forms input//
}
});
<!DOCTYPE html>
<html>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-autotab/1.9.2/js/jquery.autotab.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<div class="centered">
<form id="adder" name="commentForm" method="post">
<h2 class="formtitle">Add Contact</h2>
{{people}}
<table cellpadding="5" cellspacing="5">
<tr>
<td>Name</td>
<td>
<input class="edit" type="text" ng-model="name">
</td>
</tr>
<tr>
<td>Email</td>
<td>
<input class="edit" type="text" ng-model="email">
</td>
</tr>
<tr>
<td>Phone</td>
<td>
<input type="text" id="number" class="edit number" maxlength="3" size="3" ng-model="phone1">
<input type="text" id="number" class="edit number" maxlength="3" size="3" ng-model="phone2" /> -
<input type="text" id="number" class="edit number" maxlength="4" size="5" ng-model="phone3" />
</td>
</tr>
<tr>
<td>City</td>
<td>
<input class="edit" type="text" ng-model="city">
</td>
</tr>
<tr>
<td>State</td>
<td>
<input class="edit" type="text" ng-model="state">
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="button" value="Save" ng-click="add()">
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
请运行上面的代码片段
现在,您将代码插入数组可以使用 AUTO-TAB 正常工作。
关于JavaScript 将函数插入空白的 Angular 的 ng-repeat 数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41820175/
我的代码 "> 我想做的是 如果外层 ng-repeat 中的 n 为 0,则 div.book_container 将如下所示: 否则,di
嗨,我有一个用于 ng-repeat-start 和 end 的简单用例,并且工作正常,当我想添加内部 ng-repeat 时出现问题。 这是我的代码 {{e}} {{obj.descr
我正在查看一长串 DNA 核苷酸,并正在寻找以起始代码“AAA”开头并以终止代码“CCC”结尾的序列。由于核苷酸以三联体形式出现,因此我找到的每个序列开始和结束之间的核苷酸数必须是三的倍数。 例如,'
我有这个: .... #{item.product.codigoProduto} #{m.description} ... listRequ
我从服务请求中返回了以下 json 数据: { "entries": [{ "id": 2081, "name": "BM", "niceNam
在 Aurelia 中嵌套 repeat.for 时,内部 repeat.for 无权访问其父 repeat.for 中使用的变量>. 示例 ${x} - ${y} 在上面的示
我有一个带有类别的对象,在这个对象内部有一个名为 items 的对象,其中包含带有 items 的对象。 现在我想重复显示这样的项目: {{cat
我有... html, body { background-size: contain; background-repeat: no-repeat; } 作为我的 CS
我的问题如下:旋转时,由重复图案组成的背景发生变化,因此图案被拉伸(stretch)而不是重复。可能有什么问题? 我有这个由重复图案组成的背景: 最佳答案 您必须手动设置重复模式: parent =
关于下面的元素 如何编辑 element.style?我想要 background-repeat : no-repeat; 不确定从哪里设置它。 element { display: blo
我有一个 Observable,我想定期重复,但仅限于以下条件: apiInterface.getData() // returns Observable ... // processing is h
我无法停止 td 元素中的图像重复。它看起来很难看。我该如何解决这个问题?我也添加了 background-repeat: no-repeat 代码,但它仍然无法正常工作。请不要建议从我的 td 宽度
我想知道以下哪个示例的效果更好。如果性能相同,哪个读起来更好? 示例 1(重复选择器) .helpfulCommenter, .questionTroll { 颜色:#f00; } .question
我正在尝试创建 tooltip对于通过 ng-repeat. 创建的表的第一行 但是工具提示没有呈现。 HTML $(document).ready(function () {
我正在开发一个页面,我需要在其中显示一些框(使用 ng-repeat ),其中包含 channel 信息以及显示位置(城市)。 我面临的问题是当我重复第二个 ng-repeat : 这应该获得第一个
我在另一个 ng-repeat 中有 ng-repeat,并且两者都有分页数据。 主要的工作正常,但 ng-repeat 内的分页数据并不总是工作。它会抛出控制台错误。 错误:[$interpolat
所以我有这个小问题。我对所有项目使用 ng-repeat,我们称它们为国家,每个项目本身都有一个 ng-repeat 作为城市等子类别。我用国家/地区填充下拉菜单。 所以我有这样的国家列表: 美国 德
我有一条从 Angular $resource promise 返回的记录,如下所示。 记录是一个数组,每个记录数组中都有另一个变量数组。我尝试在我的 View 中显示如下。 div(ng-repe
我需要使用 ng-repeat 来生成多个元素,但这些元素不能分别包装在 div 内(这是用于框布局的目的,其中框布局仅适用于直接子元素)。例如,我需要这个结果: Head 1 Body 1
我已经看到(很多)许多教程和装饰器的片段 w/和 w/o 参数,包括我认为是规范答案的两个:Decorators with arguments , python decorator arguments
我是一名优秀的程序员,十分优秀!