我有一个页面可以启动包含两个 TimePicker 小部件的模态窗口。打开第一个模态时,一切正常。它也可以重新打开。但是,当打开另一个模态时,出现控制台错误:
Uncaught TypeError: Cannot read property 'apply' of undefined
at HTMLInputElement.eval (eval at globalEval (jquery.js:343), <anonymous>:851:29)
at Function.each (jquery.js:365)
at jQuery.fn.init.each (jquery.js:137)
at jQuery.fn.init.$.fn.timepicker (eval at globalEval (jquery.js:343), <anonymous>:841:21)
at HTMLDocument.eval (eval at globalEval (jquery.js:343), <anonymous>:3:107)
at fire (jquery.js:3187)
at Object.add [as done] (jquery.js:3246)
at jQuery.fn.init.jQuery.fn.ready (jquery.js:3496)
at eval (eval at globalEval (jquery.js:343), <anonymous>:1:18)
at eval (<anonymous>)
这是导致错误的代码:
//TIMEPICKER PLUGIN DEFINITION
$.fn.timepicker = function (option) {
var args = Array.apply(null, arguments);
args.shift();
return this.each(function () {
var $this = $(this),
data = $this.data('timepicker'),
options = typeof option === 'object' && option;
if (!data) {
$this.data('timepicker', (data = new Timepicker(this, $.extend({}, $.fn.timepicker.defaults, options, $(this).data()))));
}
if (typeof option === 'string') {
data[option].apply(data, args); // This is the line that causes problems
}
});
};
这是其中一个小部件的 PHP 代码:
<?= $form->field($model, 'TimeEntryStartTime',[
'showLabels'=>false
])->widget(TimePicker::classname(),[
'options' => ['placeholder' => 'Enter time...'],
]); ?>
这是启动模态的 javascript(每个都类似):
// Modal view for Monday
$('#modalButtonMonday').click(function(){
// get the click of the create button
$('#modalMonday').modal('show')
.find('#modalContentMonday')
.load($(this).attr('value'));
});
$('#modalMonday').on('hidden.bs.modal', function (e) {
// reload page when modal closed
location.reload(true);
});
最佳答案
尝试在小部件中设置不同的名称
'name'=>timepickerName;
或在“选项”html 数组中为每个插入一个 id 或类,例如。 'id'=>'timepickerId'
然后写另一个 .fn. 与相应的 name 或 id。
关于php - Yii2 Kartik TimePicker——不能在多个模式窗口中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42559328/