我已经创建了一个CalendarViewerPortlet自定义对象JS对象。在这个对象中,我存储了诸如portlet的id和上下文路径之类的东西。该对象还有许多自定义方法,其中一些用于获取/设置成员变量,另一些用于执行特定的事情。在jQuery函数里面使用“this”
当我尝试使用“this”引用对象的函数时。在jQuery函数中,它爆炸了。我知道在这种情况下,术语“这个”可能指的是别的东西,但我不确定如何解决问题并让它参照对象,就像我想要的那样。
这里是有问题的代码:
jQuery.ajax({
url: jQuery(formSel).attr("action"),
type: "POST",
data: jQuery(formSel).serialize(),
beforeSend: function(xhr) {
jQuery(msgSel).hide();
jQuery(msgSel).html("");
jQuery(tableSel).hide();
jQuery(pagerSel).hide();
jQuery(cpSelector).block({
message: "<img src='"+this.getContextPath()+"/images/icon_loading.gif' align='absmiddle' alt='Loading...' /> Fetching events..."
});
},
注的 “this.getContextPath()”。这是代码失败的地方。我试图引用我的自定义对象的getContextPath()函数。我怎样才能做到这一点?
但这就是我想要的。我希望“this”引用我的自定义对象,而不是任何jQuery。 – Zendog74 2010-07-29 20:30:26