1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| var store = { "浙江省":{ "杭州市":{ "杭州市店铺1":[], "杭州市店铺2":[], "杭州市店铺3":[] }, "宁波市":{ "宁波市店铺1":[], "宁波市店铺2":[], "宁波市店铺3":[] }, "温州市":{ "温州市店铺1":[], "温州市店铺2":[], "温州市店铺3":[] } }, "江苏省":{ "南京市":{ "南京市店铺1":[], "南京市店铺2":[], "南京市店铺3":[] }, "苏州市":{ "苏州市店铺1":[], "苏州市店铺2":[], "苏州市店铺3":[] }, "南通市":{ "南通市店铺1":[], "南通市店铺2":[], "南通市店铺3":[] } } }; var imgs = ["1.png","2.png","3.png","4.png"]; var len = imgs.length; * 生成店铺内容的具体method */ function gen(n){ var arr = []; for(var i = 0 ; i < n ; i++){ arr.push(imgs[Math.floor( Math.random() * len )]); } return arr; } _.each(store,function(value,key,list){ console.log("%s ->",key,value); var cities = value; _.each(cities,function(stores,cityName,cityList){ console.log(" %s -> ",cityName,stores); _.each(stores,function(el,storeName,storeList){ console.log(" %s -> ",storeName,el); store[key][cityName][storeName] = gen(5); }); }); }); console.log(store); JSON.stringify(store);
|