MUI 仿豆瓣电影 APP跨平台混编框架 -3(MUI系统学习总结)

10.搜索历史记录

1.通过plus.storage实现本地数据存储
2.通过plus.storage.setItem实现存
3.JavaScript:splice()
4.搜索记录中没有则直接添加到第一个元素,有查询记录,删除对应数据,并重新添加

var searchhistory = new Vue({
	el:'#list',
	data:{
		records:[]
	},
	methods:{
		open_result:function(item){
			mui.openWindow({
				id:'search-result',
				url:'./search-result.html',
				extras:{
					name:item
				}
			});
			//搜索记录排序,新搜索条件排在第一位
			searchhistory.records.remove(item);
			searchhistory.records.splice(0,0,item);
		}
	}
});


//给清除添加事件
mui('#clear')[0].addEventListener('tap',function(){
	plus.storage.setItem('history','');
	searchhistory.records = [];
});

mui.plusReady(function(){
	if(plus.storage.getItem('history') !==''){
		searchhistory.records = plus.storage.getItem('history').split(',');
	}
})

//键盘事件
document.onkeydown = function(event){
	var e = event || window.event || arguments.caller.arguments[0];
	if(e && e.keyCode == 13){
		//回车事件,搜索记录中没有则直接添加到第一个元素,有查询记录,删除对应数据
		if(searchhistory.records.contains(eval(document.getElementById('search')).value)){
			searchhistory.records.remove(eval(document.getElementById('search')).value);
		}
		searchhistory.records.splice(0,0,eval(document.getElementById('search')).value);
		plus.storage.setItem('history',searchhistory.records.toString());
		//跳转到搜索结果页面
		mui.openWindow({
			id:'search-result',
			url:'./search-result.html',
			extras:{
				name:eval(document.getElementById('search')).value
			}
		});		
	}
}


//新增属性
Array.prototype.contains = function(obj){
	var i = this.length;
	while(i--){
		if(this[i] === obj){
			return true;
		}
	}
	return false;
}

Array.prototype.indexOf = function(val){
	for(var i=0;i<this.length;i++){
		if(this[i] == val){
			return i;
		}
	}
	return -1;
}

Array.prototype.remove = function(val){
	var index = this.indexOf(val);
	if(index > -1){
		this.splice(index,1);   //splice() 方法向/从数组中添加/删除项目,然后返回被删除的项目。
	}
}

11.清除缓存

5+ plus.cache.clear 实现

mui.plusReady(function(){
	//给cache节点添加点击事件,清除缓存
	document.getElementById('cache').addEventListener('tap',function(){
		plus.cache.clear(function(){
			mui.toast('清除缓存成功');
		});
	});
})

12.页面主动加载

主动上拉加载
mui(’#pullrefresh’).pullRefresh().pullupLoading();

mui.plusReady(function(){
	name = plus.webview.currentWebview().name;
	mui('#refreshContainer').pullRefresh().pullupLoading();
})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值