内容简介:验证一个值是否已经存在数据表中
前几天Insus.NET有写过一篇《
angularjs自定义指令Directive 》
http://www.cnblogs.com/insus/p/6908815.html
仅是在程序中指定某些来值来匹配。
为你的数据表准备一个存储过程:
判断是否已经存在此值。只需写SELECT语句。如果没有记录返回,它将返回null。
有ASP.NET MVC程序中,创建model:
还要创建一个实体方法,是程序与数据协作与沟通的:
程序逻辑部分,还要写一个接口,供前端angularjs去读取:
返回给前端exists布尔值。
Ok,进行到前端angularjs时,写自定义指令Directive:
airExpressApp.directive('validateCountry', function ($http, $q) {
return {
restrict: 'AE',
require: 'ngModel',
link: function ($scope, element, attributes, ngModelController) {
ngModelController.$asyncValidators.countryExists = function (modelValue, viewValue) {
var deferred = $q.defer();
var obj = {};
obj.Country_EN = modelValue;
$http({
method: 'POST',
url: '/Code/CountryByKey',
dataType: 'json',
headers: {
'Content-Type': 'application/json; charset=utf-8'
},
data: JSON.stringify(obj),
}).then(function (response) {
if (response.data.exists) {
deferred.resolve();
} else {
deferred.reject();
}
});
return deferred.promise;
};
}
}
});
Source Code
文本框设置自定义指令属性:
实时演示:
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- MySQL数据表合并去重
- 小白学 Python 数据分析(13):Pandas (十二)数据表拼接
- PHPRAP 2.0.2 发布,接口和字段数据分离,字段使用单独数据表
- Kettle 7.1 连接HBase数据表
- 搞定PHP面试 - MySQL基础知识点整理 - 数据类型和数据表管理
- MySQL 千万级数据表 partition 实战应用
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Web Security Testing Cookbook
Paco Hope、Ben Walther / O'Reilly Media / 2008-10-24 / USD 39.99
Among the tests you perform on web applications, security testing is perhaps the most important, yet it's often the most neglected. The recipes in the Web Security Testing Cookbook demonstrate how dev......一起来看看 《Web Security Testing Cookbook》 这本书的介绍吧!