我有一个使用ng-repeat创建的表.我想为表中的每个元素添加验证.问题是每个输入单元格与其上方和下方的单元格具有相同的名称.我试图使用该{{$index}}值来命名输入,但尽管HTML中的字符串文字显示正确,但它现在正在工作.
这是我现在的代码:
<tr ng-repeat="r in model.BSM ">
<td>
<input ng-model="r.QTY" class="span1" name="QTY{{$index}}" ng-pattern="/^[\d]*\.?[\d]*$/" required/>
<span class="alert-error" ng-show="form.QTY{{$index}}.$error.pattern"><strong>Requires a number.</strong></span>
<span class="alert-error" ng-show="form.QTY{{$index}}.$error.required"><strong>*Required</strong></span>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我已经尝试删除{{}}from索引,但这也不起作用.截至目前,输入的验证属性工作正常,但不显示错误消息.
有人有什么建议吗?
编辑:除了下面的好答案,这里有一篇博客文章更详细地介绍了这个问题:http://www.thebhwgroup.com/blog/2014/08/angularjs-html-form-design-part-2 /
我希望按降序顺序收到按 "Product.Name" 排序的列表.
类似于下面按升序对列表进行排序的功能,只是相反,这可能吗?
var newList = list.OrderBy(x => x.Product.Name).ToList();
Run Code Online (Sandbox Code Playgroud) 好的,所以我有一个包含userID和taskID的临时表.它被称为CompletedTasks.我有一个包含userID和taskID的第二个表.它被称为PlannedTasks.
我需要获取已完成但未计划的所有taskID的列表.所以,我需要以某种方式从已完成的任务中清除所有行PlannedTasks.userID != CompletedTasks.userID AND PlannedTasks.taskID != CompletedTasks.taskID.
我希望这个问题有意义.如果不清楚请告诉我,我会进一步解释.
谢谢你的任何提示!
我有一个自定义验证指令,当一个字段被更改时,该指令被正确调用.但是,此字段是否有效也基于另一个字段的值.如果这是重要的,则该第二个字段是选择列表.
我想知道是否有某些方法可以在第二个表单更改时手动触发验证.也许通过使用该ng-change事件.处理这样的事情的正确方法是什么?
这是我的指示:
angular.module('myApp', []).
directive('validage', function () {
return {
require: 'ngModel',
link: function (scope, elem, attr, ngModel) {
function validate(value) {
var valid = true;
if ((GetDateDifference(new Date(value), new Date()) < 16 || GetDateDifference(new Date(value), new Date()) > 129)
&& scope.dep.DependantType == "Spouse") {
valid = false;
}
ngModel.$setValidity('validage', valid);
return value;
}
//For DOM -> model validation
ngModel.$parsers.unshift(function (value) {
var valid = true;
if ((GetDateDifference(new Date(value), new Date()) < 16 || GetDateDifference(new Date(value), new …Run Code Online (Sandbox Code Playgroud) 这是一个简单的问题(我认为),但我找不到解决方案.我知道对于其他类型的查询,您可以添加一个限制子句,使查询只返回那么多结果.这可能是实体查询吗?
var productQuery = from b in solutionContext.Version
where b.Product.ID != 1 && b.VersionNumber == b.Product.ActiveNumber
orderby b.Product.LastNumber
select b;
Run Code Online (Sandbox Code Playgroud)
我只是想这样做,所以这个查询只返回25个版本对象.谢谢你的帮助.
我有几个案例,我只是使用简单的if ... if else块.
如何减少if此代码中的语句数量?
也许我可以使用查找表,但我不确定如何在Java中实现它.
private int transition(char current, int state)
{
if(state == 0)
{
if(current == 'b')
{
return 1;
}
else
return 0;
}
if(state == 1)
{
if(current == 'a')
{
return 2;
}
else
return 0;
}
if(state == 2)
{
if(current == 's')
{
return 3;
}
else
return 0;
}
if(state == 3)
{
if(current == 'e')
{
return 3;
}
if(current == 'b')
{
return 4;
} …Run Code Online (Sandbox Code Playgroud) 我需要将一个主键添加到给定数据库中的一组表.我不知道会有多少个表或者它们的具体名称是什么.它们都是for datatable _ ##,其中##将根据我的脚本运行的各个位置而变化.
要添加主键,我使用此查询:
alter table datatable_??
add column ID int auto_increment not null first,
add primary key (ID);
Run Code Online (Sandbox Code Playgroud)
所以,我需要在数据库中的每个表上运行它.看起来我可以在PHP脚本或其他东西中做到这一点,但是它们是一种更简单的方法来在sql脚本中执行此操作吗?
我一直在使用asp.net一段时间,并且始终存在在同一行上对齐具有不同高度的对象的问题.例如,在这种情况下,我有一个搜索标签,一个文本字段,然后是一个图像按钮.让这三个项目正确对齐的"正确方法"是什么?
我现有的代码:
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Panel VerticalAlign="Center" runat="server">
<asp:Label ID="Label1" runat="server" Font-Size="X-Large" Text="Search Tests:"></asp:Label>
<asp:TextBox ID="searchTextBox" runat="server" Font-Size="X-Large"
Height="30px" style="margin-left: 13px; margin-top: 0px" Width="219px"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server" Height="45px"
ImageUrl="~/Images/SearchButton.PNG" style="margin-left: 18px; margin-top: 0px"
Width="95px" />
</asp:Panel>
</asp:Content>
Run Code Online (Sandbox Code Playgroud) 我有一个excel文件,有~10列和1-20行.我需要插入1-20行与各种数据元素.
我想知道是否有办法在excel文件中放置一些标签,以便找到并替换它们.将列标记为"名称"的东西.在代码中这样我可以说:
Name[0] = object.name;
我不确定这种确切的方法是否可行,但我真的不需要任何繁重的工作,我宁愿不对单元格位置进行硬编码,因为excel文件可能会随着时间的推移而改变.
我还必须在行中添加隐藏的"ID"单元格.我想我以后可以越过那座桥了.
所以,我觉得这个很直接.
这是我的代码:
Dictionary<int, IEnumerable<SelectListItem>> fileTypeListDict = new Dictionary<int, IEnumerable<SelectListItem>>();
foreach (PresentationFile pf in speakerAssignment.FKPresentation.PresentationFiles)
{
IEnumerable<SelectListItem> fileTypes = Enum.GetValues(typeof(PresentationFileType))
.Cast<PresentationFileType>().Select(x => new SelectListItem
{
Text = x.ToString(),
Value = Convert.ToString((int)x),
Selected = pf.Type == (int)x
});
fileTypeListDict.Add(pf.ID, fileTypes);
}
Run Code Online (Sandbox Code Playgroud)
发生的事情是,最后字典将具有所有正确的键,但所有值将被设置为fileTypes在循环的最后一次迭代期间创建的列表.我确信这与用作参考的对象有关,但在我使用C#之前没有看到过这个问题.任何人都在意解释为什么会这样,以及我应该如何解决这个问题?
谢谢!
c# ×4
angularjs ×2
html ×2
mysql ×2
validation ×2
.net ×1
asp.net ×1
css ×1
database ×1
excel ×1
foreach ×1
grid ×1
if-statement ×1
java ×1
javascript ×1
list ×1
optimization ×1
primary-key ×1
reference ×1
sorting ×1
sql ×1
sql-order-by ×1