jQuery Mobile 页面刷新机制
我很难理解 jQuery Mobile 如何在 ajax 更新后处理页面刷新。
我有一个两页的独特文件网站:一个搜索引擎。
第一页是搜索字段。提交会触发 JSON 调用和解析器,从而更新第二页:结果。
现在我正在使用: $.mobile.changePage( $('#result') );
它可以很好地完成从搜索字段到结果页面的工作。 然而: 如果我在下一个/上一个页面的结果页面中重用它(新的 json 调用、新的解析、DOM 中新添加的节点); Jquery Mobile 只是不“绘制”新添加的节点。
谁能解释一下,请使用和区别 1- $.mobile.page()
2- $.mobile.changePage()
3- $.mobile.refresh()
或给我一个关于如何处理页面更改的提示。 谢谢!
I'm having a lot of pain understanding how jQuery Mobile handles pages refresh after an ajax update.
I'm having a two pages - unique file site: a search engine.
First page is a search field. Submit triggers a JSON call and parser which updates the second page: results.
for now i'm using: $.mobile.changePage( $('#result') );
which does the job great from search field to result page.
However:
If I reuse it from result page for next/prev pages ( new json call, new parse, new added nodes in the DOM );
Jquery Mobile just don't "paint" the newly added nodes.
can anyone explain, please the use and distinction of
1- $.mobile.page()
2- $.mobile.changePage()
3- $.mobile.refresh()
or give me a hint on how I should handle page changes.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
摘自这里 http ://scottwb.com/blog/2012/06/29/reload-the-same-page-without-blinking-on-jquery-mobile/ 也在 jQuery Mobile 上进行了测试1.2.0
Taken from here http://scottwb.com/blog/2012/06/29/reload-the-same-page-without-blinking-on-jquery-mobile/ also tested on jQuery Mobile 1.2.0
请仔细看看这里: http://jquerymobile.com/test/docs/api /methods.html
$.mobile.changePage()
是从一个页面切换到另一个页面,参数可以是url,也可以是page对象。 (只有 #result 也可以)不再推荐
$.mobile.page()
,请使用.trigger( "create")
,另请参阅:JQuery Mobile .page() 函数导致无限循环?重要提示:
创建与刷新:重要区别
请注意,某些小部件的创建事件和刷新方法之间存在重要区别。 create 事件适合增强包含一个或多个小部件的原始标记。某些小部件具有的刷新方法应该用于已通过编程方式操作并需要更新 UI 来匹配的现有(已增强)小部件。
例如,如果您有一个页面,在创建页面后使用 data-role=listview 属性动态附加新的无序列表,则在该列表的父元素上触发 create 会将其转换为 listview 样式的小部件。如果随后以编程方式添加更多列表项,则调用列表视图的刷新方法将仅将这些新列表项更新为增强状态,并保持现有列表项不变。
我猜
$.mobile.refresh()
不存在那么您使用什么来获取结果?列表视图?然后您可以通过执行以下操作来更新它:
示例:
http:// /operationmobile.com/dont-forget-to-call-refresh-when-adding-items-to-your-jquery-mobile-list/
否则你可以这样做:
Please take a good look here: http://jquerymobile.com/test/docs/api/methods.html
$.mobile.changePage()
is to change from one page to another, and the parameter can be a url or a page object. ( only #result will also work )$.mobile.page()
isn't recommended anymore, please use.trigger( "create")
, see also: JQuery Mobile .page() function causes infinite loop?Important:
Create vs. refresh: An important distinction
Note that there is an important difference between the create event and refresh method that some widgets have. The create event is suited for enhancing raw markup that contains one or more widgets. The refresh method that some widgets have should be used on existing (already enhanced) widgets that have been manipulated programmatically and need the UI be updated to match.
For example, if you had a page where you dynamically appended a new unordered list with data-role=listview attribute after page creation, triggering create on a parent element of that list would transform it into a listview styled widget. If more list items were then programmatically added, calling the listview’s refresh method would update just those new list items to the enhanced state and leave the existing list items untouched.
$.mobile.refresh()
doesn't exist i guessSo what are you using for your results? A listview? Then you can update it by doing:
Example:
http://operationmobile.com/dont-forget-to-call-refresh-when-adding-items-to-your-jquery-mobile-list/
Otherwise you can do:
我在 jQuery 论坛上发布了这一点(我希望它能有所帮助):
I posted that in jQuery forums (I hope it can help):
我发现这个线程希望使用 jQuery Mobile 创建 ajax 页面刷新按钮。
@sgissinger 有最接近我正在寻找的答案,但它已经过时了。
我更新了 jQuery Mobile 1.4
I found this thread looking to create an ajax page refresh button with jQuery Mobile.
@sgissinger had the closest answer to what I was looking for, but it was outdated.
I updated for jQuery Mobile 1.4
我通过在我想要刷新的页面上的页面 div 中使用 data-cache="false" 属性解决了这个问题。
就我而言,这是我的购物车。如果客户将一件商品添加到购物车,然后继续购物,然后将另一件商品添加到购物车,则购物车页面将不会显示新商品。除非他们刷新页面。据我所知,将 data-cache 设置为 false 指示 JQM 不要缓存该页面。
希望这对将来的其他人有帮助。
I solved this problem by using the the data-cache="false" attribute in the page div on the pages I wanted refreshed.
In my case it was my shopping cart. If a customer added an item to their cart and then continued shopping and then added another item to their cart the cart page would not show the new item. Unless they refreshed the page. Setting data-cache to false instructs JQM not to cache that page as far as I understand.
Hope this helps others in the future.
这个答案对我有用 http:// view.jquerymobile.com/master/demos/faq/injected-content-is-not-enhanced.php。
在多页面模板的上下文中,我修改了 Javascript 'pagebeforeshow' 处理程序和触发器中
的内容脚本末尾刷新:
This answer did the trick for me http://view.jquerymobile.com/master/demos/faq/injected-content-is-not-enhanced.php.
In the context of a multi-pages template, I modify the content of a
<div id="foo">...</div>
in a Javascript 'pagebeforeshow' handler and trigger a refresh at the end of the script: