5

我正在尝试学习自己的 jQuery Mobile。我认为这真的很酷,但我被困在了一些事情上。如果我想这样称呼:

$j.mobile.changePage({ url: $j("#News"), data: "apple=banana", type: "GET"}, "slide", true, true);

它似乎不起作用。我不知道用 jQuery 传递数据,所以也许我做错了什么。

亲切的问候,森内

编辑:对不起,把错误的代码放在那里......

4

3 回答 3

1

基于反复试验,这就是我看到的情况:

  • $.mobile.changePage ('#'+id, filter, false, true) 刷新当前视图但不在服务器上执行请求
  • $.mobile.changePage ({url:'#'+id, data:'code=apple=banana', type:'GET'}, 'slide', false, true) 不会刷新当前视图但会执行服务器上的请求
  • $.mobile.changePage ({url:'http://localhost/SomeOtherPage.aspx', data:'code=apple=banana', type:'GET'}, 'slide', false, true) 刷新当前视图并在服务器上执行请求

因此,似乎基本 URL 必须不同才能在服务器上执行时更新当前视图。

于 2010-12-31T18:22:51.050 回答
1

据我所知 - url 必须是真实的 url另一个的 iddiv[data-role=page]

澄清:

提供 ID 会显示当前文档中可用的另一个 div(您可以创建包含多个页面的 html 文件)。

另外 - jquerymobile 只加载一次页面,并将其添加到文档中以供以后参考。以后不会触发任何服务器端操作。(我不确定它如何处理提供数据的调用)

于 2010-12-22T07:30:15.640 回答
0

I ran into a scenario where I needed to capture a tap event on an item and display a loaded page (same html file) with details for the tapped item. The solution I found is semi-dependent on a few things, however:

  • Your .js scheme should be contained within at least one "namespace", or property off of the global object, to prevent writing over anything important to the global object or being written over by external code.
  • Your data must already be present in a .js object and or accessible by some other means.

Attaching a tap event to the element causing the page transition (or even ina function causing a page transition problematically) allows you to create a function as follows:

function PageTransitionHandle(oEvent)
{
   // Set your stored data to a global object
   oYourNamespace.DataObject = oDataObject;

   // not necissary if already linked to other page but useful when attaching to
   // an image  or other element
   $.mobile.changePage("#otherPageId");
}

and in the pageshow event for the next page:

function PageInit()
{
   var oPageData = oYourNamespace.DataObject;
   // Handle using data from here (i.e calling webmethod using parameters 
   // or setting data according to object)
}

Potentially this should work with external pages and internal pages since ajax loading methods are used, but I have not tested. This is useful for passing parameters or even whole data objects to define other feilds, or letting a users information follow them, anything really.

Another route to look at is Local Storage but I haven't personally looked at this much yet

于 2013-02-01T19:39:31.747 回答