当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery mobile - how to vary option in function call?

问题描述:

I'm trying to mesh together two Jquery mobile plugins. Both are using the same core functions, but one adds one options, which keeps the other plugin from working.

The function is called like this:

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

}

);

with pageContainer only being used by one function.

My question:

Is there a way to differentiate within the options or do I have to do something like this:

if (called by plugin one) {

function with option

} else if (called by plugin two){

function without option

}

There must be nicer ways to do this?

Thanks for some input!

网友答案:

Dimension your object outside your call and test to see if you require the additional parameter:

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);
分享给朋友:
您可能感兴趣的文章:
随机阅读: