fix(form): 修复 form.val 第二个参数为 ArrayLike 时表单赋值异常 (#2455)

pull/2462/head^2
morning-star 2025-01-16 16:08:31 +08:00 committed by GitHub
parent 0cde55a43d
commit 317512bbb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View File

@ -105,9 +105,12 @@ layui.define(['lay', 'layer', 'util'], function(exports){
var itemForm = $(this); var itemForm = $(this);
// 赋值 // 赋值
layui.each(object, function(key, value){ for(var key in object){
var itemElem = itemForm.find('[name="'+ key +'"]') if(!lay.hasOwn(object, key)) continue;
,type;
var type;
var value = object[key];
var itemElem = itemForm.find('[name="'+ key +'"]');
// 如果对应的表单不存在,则不执行 // 如果对应的表单不存在,则不执行
if(!itemElem[0]) return; if(!itemElem[0]) return;
@ -123,7 +126,7 @@ layui.define(['lay', 'layer', 'util'], function(exports){
} else { // 其它类型的表单 } else { // 其它类型的表单
itemElem.val(value); itemElem.val(value);
} }
}); };
}); });
form.render(null, filter); form.render(null, filter);

View File

@ -770,6 +770,11 @@
listener, listener,
lay.passiveSupported ? { passive: true, capture: useCapture } : useCapture lay.passiveSupported ? { passive: true, capture: useCapture } : useCapture
); );
}
var hasOwnProperty = Object.prototype.hasOwnProperty;
lay.hasOwn = function(obj, prop){
return hasOwnProperty.call(obj, prop);
}; };