我将两个值存储到数组中。他们是年龄和名字。如何使用$ localStorage存储此数组?刷新页面时,数组和$ localStorage都为空。
var app=angular.module("plunker",["ngStorage"]);
app.controller("xCtrl",function($scope,$rootScope,$localStorage){
$scope.list=[]
$scope.x={}
$scope.add=function(x){
$scope.list.push(x);
$localStorage.list= $scope.list;
$scope.$storage= $localStorage.list
$scope.x={}
}
})
答案 0 :(得分:1)
这应该是您的控制器代码
import urllib.request
from bs4 import BeautifulSoup
import traceback
from time import localtime, strftime
def display(result):
print ('Weather in Suwon, Asia at ' + strftime('%H:%M', localtime()) + '\n')
print ('Condition: ' + result['cond'])
print ('Temparature: ' + result['temp'] + u"\N{DEGREE SIGN}" + 'C')
print ('RealFeel: ' + result['realfeel'] + u"\N{DEGREE SIGN}" + 'C')
print (result['humid'])
print (result['cloud'])
print
def main():
with urllib.request.urlopen("http://www.accuweather.com/en/kr/suwon/223670/current-weather/223670") as url:
html = url.read()
soup = BeautifulSoup(html,"lxml")
soup = soup.find('div', {'id':'detail-now'})
result = {}
while soup:
if soup.get('class') == 'cond':
result['cond'] = soup.text
elif soup.get('class') == 'temp':
result['temp'] = soup.text.replace("°", "")
elif soup.get('class') == 'realfeel':
s = soup.text.replace("°", "")
result['realfeel'] = s.replace("RealFeel® ", "")
elif soup.get('cellspacing') == None and soup.get('class') == 'stats':
ss = soup.findAll('li')
for li in ss:
if 'humid' in li.text:
result['humid'] = li.text.replace(":", ": ")
elif 'Cloud' in li.text:
result['cloud'] = li.text.replace(":", ": ")
break
soup = soup.findNext()
display(result)
if __name__ == "__main__":
try:
main()
except:
traceback.print_exc()