在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 這兩個(gè)方法中有這個(gè)each()方法嗎?下邊這段代碼這如何理解?

這兩個(gè)方法中有這個(gè)each()方法嗎?下邊這段代碼這如何理解?

首先:非套答案,確實(shí)有點(diǎn)看不,確實(shí)有點(diǎn)看不明白,求解!

function getMatchedData(data,match){
            var result = data;
            var attrs = _______;
            attrs.each(function(obj){
                result = typeof result == 'object' && result.hasOwnProperty(obj) ? _____ : ______;
            });
            result = typeof result == "undefind" ? "" : result;
            return result;
        }

        function templateDataMapping(temp,data){
            if(temp){
                var matches = temp.match(/{{[a-z_A-Z](\w+)?([\.][a-z_A-Z](\w+)?)*}}/g);
                matches.each(function(index,match){
                    temp = temp.replace(match,getMatchedData(data,match.substring(2,match.length-2)));
                })
            }
            return temp;
        }
回答
編輯回答
清夢

上面的方法遍歷的參數(shù)attrs是對象,所以each方法中的參數(shù)obj是對象,下面方法遍歷的參數(shù)matchs是正則匹配后返回的數(shù)組,是一個(gè)數(shù)組,所以each的參數(shù)是index索引和match索引對應(yīng)的值。

2017年7月4日 04:32
編輯回答
你好胸

這應(yīng)該是一個(gè)實(shí)現(xiàn)moustache語法,首先不能寫each應(yīng)該是forEach,而且其中有一個(gè)undefined你寫錯(cuò)了。第一個(gè)空應(yīng)該是個(gè)數(shù)組也就是 match.split('.'),第二個(gè)很明顯是result[obj],然后第三個(gè)是 undefined。

2017年7月28日 05:05