Skip to content

Commit

Permalink
修复fn.js和php.js里foreach函数可能在安卓系统下报错,ios无此bug
Browse files Browse the repository at this point in the history
  • Loading branch information
logoove committed Oct 6, 2024
1 parent af32d2e commit c77dc69
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
41 changes: 21 additions & 20 deletions weui/js/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,26 +819,27 @@ export function $_COOKIE(b){let d=0,g="",f=b+"=",a=document.cookie.split(";"),e=
* @param 处理方法函数
* @returns 循环输出
*/
export function foreach(arr, handler) {
let k, it, pair;
if (arr && typeof arr === 'object' && arr.change_key_case) { // Duck-type check for our own array()-created PHPJS_Array
return arr.foreach(handler);
}
if (handler.length === 1) {
for (k in arr) {
if (arr.hasOwnProperty(k)) {
handler(arr[k]); // only pass the value
}
}
}
else {
for (k in arr) {
if (arr.hasOwnProperty(k)) {
handler(k, arr[k]);
}
}
}
}
export function foreach(obj,callback){
if("length" in obj){
for(let i =0;i<obj.length;i++){
let item = obj[i];
let res = callback && callback.call(item,i,item);
if(res === false){
break;
}
}
}else{
for(let key in obj){
if(obj.hasOwnProperty(key)){
let value = obj[key];
let res = callback && callback.call(value,key,value);
if(res === false){
break;
}
}
}
}
}

/**
* preg_match('a','abc') true
Expand Down
22 changes: 21 additions & 1 deletion weui/js/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,27 @@ function $_COOKIE(b){var d=0,g="",f=b+"=",a=document.cookie.split(";"),e=a.lengt
* @param 处理方法函数
* @returns 循环输出
*/
function foreach(a,d){var b,c,e;if(a&&typeof a==="object"&&a.change_key_case){return a.foreach(d)}if(typeof this.Iterator!=="undefined"){var c=this.Iterator(a);if(d.length===1){for(e in c){d(e[1])}}else{for(e in c){d(e[0],e[1])}}}else{if(d.length===1){for(b in a){if(a.hasOwnProperty(b)){d(a[b])}}}else{for(b in a){if(a.hasOwnProperty(b)){d(b,a[b])}}}}};
function foreach(obj,callback){
if("length" in obj){
for(let i =0;i<obj.length;i++){
let item = obj[i];
let res = callback && callback.call(item,i,item);
if(res === false){
break;
}
}
}else{
for(let key in obj){
if(obj.hasOwnProperty(key)){
let value = obj[key];
let res = callback && callback.call(value,key,value);
if(res === false){
break;
}
}
}
}
}

/**
* preg_match('a','abc') true
Expand Down

0 comments on commit c77dc69

Please sign in to comment.