【问题标题】:jquery mobile - how to vary option in function call?jquery mobile - 如何在函数调用中改变选项?
【发布时间】:2011-10-12 21:09:53
【问题描述】:

我正在尝试将两个 Jquery 移动插件结合在一起。两者都使用相同的核心功能,但其中一个添加了一个选项,这使另一个插件无法工作。

函数是这样调用的:

$.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
       }

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

感谢您的意见!

【问题讨论】:

    标签: jquery function jquery-mobile options


    【解决方案1】:

    在您的调用之外测量您的对象并测试您是否需要附加参数:

    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);
    

    【讨论】:

      猜你喜欢
      • 2013-11-09
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      • 2016-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多