Eas*_*syE -1 javascript jquery
目前的问题:
我想验证我的JavaScript对象是空的,我试图使用以下JQuery函数jQuery.isEmptyObject但是,这不会返回预期的结果.
示例:
var searchRequest = {
marketId: "",
officeId: "",
partnerId: "",
statusId: ""
}
if (jQuery.isEmptyObject(searchRequest)) {
$("#searchButton").prop('disabled', true);
}
Run Code Online (Sandbox Code Playgroud)
题:
如何使用JQuery验证JavaScript对象是否为空.
emptyObject表示没有任何属性的对象.不是具有空属性的对象.
/**
* @param emptyCheck Function that takes a value and returns true if it's empty to allow for flexible
* definition of a value being empty. Defaults to a simple `!` check
*/
function areAllPropsEmpty(obj, emptyCheck) {
emptyCheck = emptyCheck || (val)=> !val;
for (var prop in obj) {
if (emptyCheck(obj[prop])) return false;
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
557 次 |
| 最近记录: |