2011-10-12 18 views
1

我试图将两个Jquery移动插件网格化在一起。两者都使用相同的核心功能,但增加了一个选项,使其他插件无法正常工作。jquery mobile - 如何更改函数调用中的选项?

该函数的调用这样的:

$.mobile.changePage(
      url, 
      { 
      type: type && type.length && type.toLowerCase() || "get", 
      data: $this.serialize(), 
      transition: $this.jqmData("transition"), 
      direction: $this.jqmData("direction"), 
      reloadPage: true, 
      pageContainer:$currPanel 
      } 
    ); 

与pageContainer仅正在使用的一个功能。

我的问题: 是有办法的选项中分化或我必须做这样的事情:

if (called by plugin one) { 
    function with option 
    } else if (called by plugin two){ 
     function without option 
     } 

必须有更好的方法来做到这一点?

感谢您的一些意见!

回答

0

尺寸您您的垂询和测试之外对象,以确定您所需要的附加参数:

var myOptions = { 
    type: type && type.length && type.toLowerCase() || "get", 
    data: $this.serialize(), 
    transition: $this.jqmData("transition"), 
    direction: $this.jqmData("direction"), 
    reloadPage: true, 
}; 

if (caller == someVariable) { 
    myOptions.pageContainer = $currPanel; 
} 

$.mobile.changePage(url, myOptions); 
+0

抱歉这么晚才回复。现在试试这个... – frequent

相关问题