// 保存 var switchList = 0; if(that.dingdan){ switchList += Math.pow(2,0); }; if(that.vipCard){ switchList += Math.pow(2,1); }; if(that.coupon){ switchList += Math.pow(2,2); }; if(that.chuzhi){ switchList += Math.pow(2,3); }; if(that.score){ switchList += Math.pow(2,4); }; if(that.address){ switchList += Math.pow(2,5); }; if(that.shopCar){ switchList += Math.pow(2,6); }; if(that.indexPage){ switchList += Math.pow(2,7); }; console.log(switchList);
// 取值 if(data && data.ret == 0){ var userCenterCustom = data.model.userCenterCustom; if((userCenterCustom & (Math.pow(2,0))) != 0){ vm.dingdan = true; } else { vm.dingdan = false; }; if((userCenterCustom & (Math.pow(2,1))) != 0){ vm.vipCard = true; } else { vm.vipCard = false; }; if((userCenterCustom & (Math.pow(2,2))) != 0){ vm.coupon = true; } else { vm.coupon = false; }; if((userCenterCustom & (Math.pow(2,3))) != 0){ vm.chuzhi = true; } else { vm.chuzhi = false; }; if((userCenterCustom & (Math.pow(2,4))) != 0){ vm.score = true; } else { vm.score = false; }; if((userCenterCustom & (Math.pow(2,5))) != 0){ vm.address = true; } else { vm.address = false; }; if((userCenterCustom & (Math.pow(2,6))) != 0){ vm.shopCar = true; } else { vm.shopCar = false; }; if((userCenterCustom & (Math.pow(2,7))) != 0){ vm.indexPage = true; } else { vm.indexPage = false; }; }
圖一 switchList 和 圖二 userCenterCustom 的值相同javascript