项目中遇到的一个问题,同一个页面有两个地方需要做MUI下拉刷新初始化操作,按照官方文档来的话只能初始化一个。于是在百度搬来了一个方法,需要修改mui.js 2940行左右的源码,亲测有效,先粘代码:
/**
* mui.init pulldownRefresh
* @param {type} $
* @returns {undefined}
*/
(function($) {
$.addInit({
name: 'pullrefresh',
index: 1000,
handle: function() {
var options = $.options;
/********** 修改的代码 **********/
var pullRefreshOptionsS = options.pullRefresh || {};
pullRefreshOptionsS = Object.prototype.toString.call(pullRefreshOptionsS) == '[object Array]'
? pullRefreshOptionsS : [pullRefreshOptionsS];
for (var pp in pullRefreshOptionsS) {
pullRefreshOptions = pullRefreshOptionsS[pp];
/********** 修改的代码 **********/
var hasPulldown = pullRefreshOptions.down && pullRefreshOptions.down.hasOwnProperty('callback');
var hasPullup = pullRefreshOptions.up && pullRefreshOptions.up.hasOwnProperty('callback');
在mui.init的时候,将官网DEMO中原来的对象改成一个数组就OJBK了。
mui.init({
pullRefresh: [{
container: '#content_task_list',
down: {
callback: pulldownRefreshTask
},
up: {
contentrefresh: '正在加载...',
callback: pullupRefreshTask
}
}, {
container: '#content_defect_list',
down: {
callback: pulldownRefreshDefect
},
up: {
contentrefresh: '正在加载...',
callback: pullupRefreshDefect
}
}]
});