我们将prototype.js用于javascript,但我们现在正在实现Kendo UI DatePicker,我对如何处理问题感到困惑。鉴于以下内容:
function MyClass()
{
this.Name = $('inputName');
this.LastName $('inputLastName');
this.GridViewInputs;
}
MyClass.prototype.init = function()
{
//some event observe methods here
}
MyClass.protype.setUpDatePickers = function()
{
//grab all input values from a gridview and attach a date picker to each
this.GridViewInputs = $$('.Dates');
//HERE IS MY PROBLEM, I AM NOT SURE HOW TO CALL THE FUNCTION BELOW FROM HERE
//AND PASSING IT EACH INPUT
}
$j(document).ready(function() {
// create DatePicker from input HTML element
$(myInput passed here).kendoDatePicker();
});
我遇到的问题是我无法在$ j函数中使用this.GridViewInputs,因为它会说它无法识别,我相信因为它在对象之外。
答案 0 :(得分:1)
为什么不在文档就绪函数中调用setUpDatePickers
方法?
调用它的两种方法 - 在创建MyClass
var t = new MyClass();
t.setupDatePickers();
或直接来自原型
MyClass.protype.setUpDatePickers()
如果你直接从原型中调用它,你没有this
可用 - 所以它可能不是最好的方式
同样在MyClass.protype.setUpDatePickers
内部将日期选择器放在输入上你需要执行以下操作之一 - 我不确定第一个是否会起作用,因为我之前没有使用过kendo - 但第二个会起作用。
$$('.Dates').invoke('kendoDatePicker');
//
//OR
//
$$('.Dates').each(function(input){
input.kendoDatePicker();
});