Authored by 毕凯

省市区地址列表增加缓存 code review by @liangzhifeng

... ... @@ -21,6 +21,7 @@ var $addressForm = $('.edit-address'),
isSubmiting,
currentPage = 'edit',
newArea = [],
chinaAddressList,
queryString = $.queryString();
$($editAddressPage, $addressListPage).css('min-height', function() {
... ... @@ -118,12 +119,7 @@ $submit.on('touchend', function() {
$(this).removeClass('highlight');
});
// 省市区列表异步加载
$.ajax({
method: 'GET',
url: '/home/locationList',
timeout: 60000
}).then(function(html) {
function bindAddressListEvent(html) {
$addressListPage.html(html);
// 省市区
... ... @@ -185,6 +181,27 @@ $.ajax({
}).on('touchend touchcancel', 'li', function() {
$(this).removeClass('highlight');
});
}).fail(function() {
}
// 读取省市区列表缓存
if (window.localStorage && window.localStorage.getItem) {
chinaAddressList = window.localStorage.getItem('chinaAddressList');
}
if (chinaAddressList) {
bindAddressListEvent(chinaAddressList);
} else {
// 省市区列表异步加载
$.ajax({
method: 'GET',
url: '/home/locationList',
timeout: 60000
}).then(function(html) {
bindAddressListEvent(html);
if (window.localStorage && window.localStorage.setItem) {
window.localStorage.setItem('chinaAddressList', html);
}
}).fail(function() {
tip.show('获取省市区列表失败');
});
});
}
... ...