AngularJS用方括号验证和字段名 [英] AngularJS validation and field name with square brackets

查看:184
本文介绍了AngularJS用方括号验证和字段名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面这个教程 http://scotch.io/tutorials/javascript/ angularjs形式验证但我必须用方括号表单字段(例如company_bundle_task [timeStart] [日期] - 通过Symfony2的渲染)和验证在这些领域行不通,比如这个:

I'm following this tutorial http://scotch.io/tutorials/javascript/angularjs-form-validation but I have form fields with square brackets ( for example company_bundle_task[timeStart][date] - rendered by Symfony2 ) and validation on those fields doesn't work, for example this:

<span class="help-block" ng-show="company_bundle_task.company_bundle_task[timeStart][date].$invalid">Required</span>

<span class="help-block" ng-show="company_bundle_task.company_bundle_task[timeStart][date].$error.required">Required</span>

他们从未显示,即使这些字段是无效的/空的/ etc。

they are never shown, even though those fields are invalid/empty/etc.

推荐答案

您必须逃离引号你的名字,因为a.example相当于一个['例如']你可以写的:

You have to escape your name in quotes, since a.example is equivalent of a['example'] you can write:

<span class="help-block" ng-show="company_bundle_task['company_bundle_task[timeStart][date]'].$error.required">Required</span>

这篇关于AngularJS用方括号验证和字段名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆