mirror of https://github.com/layui/layui
新增 `laydate.reload()` 用法,用于重载组件实例
parent
c20b6b4798
commit
f46742858e
|
@ -56,18 +56,22 @@
|
||||||
|
|
||||||
// 操作当前实例
|
// 操作当前实例
|
||||||
var thisModule = function(){
|
var thisModule = function(){
|
||||||
var that = this
|
var that = this;
|
||||||
,options = that.config
|
var options = that.config;
|
||||||
,id = options.id;
|
var id = options.id;
|
||||||
|
|
||||||
thisModule.that[id] = that; //记录当前实例对象
|
thisModule.that[id] = that; // 记录当前实例对象
|
||||||
|
|
||||||
return that.inst = {
|
return that.inst = {
|
||||||
//提示框
|
// 提示框
|
||||||
hint: function(content){
|
hint: function(content){
|
||||||
that.hint.call(that, content);
|
that.hint.call(that, content);
|
||||||
}
|
},
|
||||||
,config: that.config
|
// 重载实例
|
||||||
|
reload: function(options){
|
||||||
|
that.reload.call(that, options);
|
||||||
|
},
|
||||||
|
config: that.config
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -212,6 +216,13 @@
|
||||||
};
|
};
|
||||||
return text[options.lang] || text['cn'];
|
return text[options.lang] || text['cn'];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 重载实例
|
||||||
|
Class.prototype.reload = function(options){
|
||||||
|
var that = this;
|
||||||
|
that.config = lay.extend({}, that.config, options);
|
||||||
|
that.init();
|
||||||
|
};
|
||||||
|
|
||||||
//初始准备
|
//初始准备
|
||||||
Class.prototype.init = function(){
|
Class.prototype.init = function(){
|
||||||
|
@ -348,7 +359,8 @@
|
||||||
|
|
||||||
//获取限制内日期
|
//获取限制内日期
|
||||||
lay.each(['min', 'max'], function(i, item){
|
lay.each(['min', 'max'], function(i, item){
|
||||||
var ymd = [], hms = [];
|
var ymd = [];
|
||||||
|
var hms = [];
|
||||||
if(typeof options[item] === 'number'){ //如果为数字
|
if(typeof options[item] === 'number'){ //如果为数字
|
||||||
var day = options[item]
|
var day = options[item]
|
||||||
,tDate = new Date()
|
,tDate = new Date()
|
||||||
|
@ -368,9 +380,11 @@
|
||||||
);
|
);
|
||||||
ymd = [thisDate.getFullYear(), thisDate.getMonth() + 1, thisDate.getDate()];
|
ymd = [thisDate.getFullYear(), thisDate.getMonth() + 1, thisDate.getDate()];
|
||||||
hms = [thisDate.getHours(), thisDate.getMinutes(), thisDate.getSeconds()];
|
hms = [thisDate.getHours(), thisDate.getMinutes(), thisDate.getSeconds()];
|
||||||
} else {
|
} else if(typeof options[item] === 'string') {
|
||||||
ymd = (options[item].match(/\d+-\d+-\d+/) || [''])[0].split('-');
|
ymd = (options[item].match(/\d+-\d+-\d+/) || [''])[0].split('-');
|
||||||
hms = (options[item].match(/\d+:\d+:\d+/) || [''])[0].split(':');
|
hms = (options[item].match(/\d+:\d+:\d+/) || [''])[0].split(':');
|
||||||
|
} else if(typeof options[item] === 'object'){
|
||||||
|
return options[item];
|
||||||
}
|
}
|
||||||
options[item] = {
|
options[item] = {
|
||||||
year: ymd[0] | 0 || new Date().getFullYear()
|
year: ymd[0] | 0 || new Date().getFullYear()
|
||||||
|
@ -2169,12 +2183,19 @@
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
//核心接口
|
// 渲染 - 核心接口
|
||||||
laydate.render = function(options){
|
laydate.render = function(options){
|
||||||
var inst = new Class(options);
|
var inst = new Class(options);
|
||||||
return thisModule.call(inst);
|
return thisModule.call(inst);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 重载
|
||||||
|
laydate.reload = function (id, options) {
|
||||||
|
var that = thisModule.getThis(id);
|
||||||
|
if(!that) return;
|
||||||
|
return that.reload(options);
|
||||||
|
};
|
||||||
|
|
||||||
// 获取对应 ID 的实例
|
// 获取对应 ID 的实例
|
||||||
laydate.getInst = function (id) {
|
laydate.getInst = function (id) {
|
||||||
var that = thisModule.getThis(id);
|
var that = thisModule.getThis(id);
|
||||||
|
|
Loading…
Reference in New Issue