【发布时间】:2014-06-09 09:45:37
【问题描述】:
我在 jquery 中使用了一个函数,它从服务器端获取所有值,然后根据这些值,在客户端执行一些验证。下面是我用过的代码
AOT.View.AssetMarkTrustTrust.prototype.validateSubmit = function () {
var result = false;
var message = '';
result = applicationView.GetCardEmbossings();//this method will get the values from the server side
if (result != null)
$.each(result, function () {
if ((result.CardEmbossingLine1.Length > 26) ||
(!string.IsNullOrEmpty(result.CardEmbossingLine2) && result.CardEmbossingLine2.Length > 26) && !result.Suppress) {
AOT.Utility.displayWarning("Please use Card/Check Editor to specify name that will be printed on card, 26 characters max.");
return false;
}
});
if (!result && !AOT.Utility.isNullEmptyUndefined(message)) {
AOT.Utility.displayWarning(message, '');
}
return result;
};
问题是当我检查值 CardEmbossingLine1 的长度时,它显示为未定义。但是,对象结果下有值。我无法满足条件,因为对象下的不同值未定义,因此条件没有被触发。请让我知道我错过了哪里。
谢谢
【问题讨论】:
-
在代码后面放一个console.log:result = applicationView.GetCardEmbossings();并分析对象的结构
-
applicationView.GetCardEmbossings();这是在进行 ajax 调用吗? -
是的,它正在进行 ajax 调用
-
@Yash:请阅读我链接到的线程。会很清楚的。
标签: jquery asp.net-mvc foreach