如何留住JSON对象在onsenui多个插件,模板页面? [英] How to retain json objects in multiple ons-template pages in onsenui?

查看:135
本文介绍了如何留住JSON对象在onsenui多个插件,模板页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我填充JSON对象在阿贾克斯。在导航页面,它保留了所有的JSON对象。但是,当我切换到另一个模板(page2.html),它不保留JSON对象。 我需要填充的用户ID,acc_nbr(在code提及)其他附件模板的页面。

任何有关此帮助?
这是我的code。

 <脚本>
$(文件)。就绪(函数(){
    $阿贾克斯({
          键入:GET,
          网址:控制器记号= 123?,
          数据类型:JSON,
          成功:功能(数据){
          $('#用户ID)HTML(data.userid);
          $('#acc_nbr)HTML(data.accountnbr);
          },
          错误:函数(){
            警报(对不起!);
          }
        });

});
< / SCRIPT>
 

index.html的

 < ONS-导航动画=幻灯片VAR =app.navi>
    <附件页>
    /*/ 内容 /*/
     < D​​IV ID =用户id>< / DIV>
    < /附件页>
    < /附件导航仪>

    < ONS-模板ID =page2.html>
    <附件页>
    /*/ 内容 /*/
    < D​​IV ID =acc_nbr>< / DIV>
    < /附件页>
    < /插件模板>
 

解决方案

尝试添加到您<脚本> 部分。

  $(document.body的)。在(pageinit,#page2.html,函数(){
   //调用同一个AJAX功能
}
 

Here I am populating json objects in ajax. In navigator page, it retains all the json objects. But when I switch to another template (page2.html), it doesn't retain the json objects. I need to populate the userid, acc_nbr(mentioned in the code) in other ons-template pages.

Any help regarding this?
Here is my code.

<script>
$(document).ready(function(){
    $.ajax({
          type: "GET",
          url: "Controller?token=123",
          dataType: 'json',
          success: function(data){
          $('#userid').html(data.userid);     
          $('#acc_nbr').html(data.accountnbr);      
          },
          error:function(){
            alert("Sorry!");
          }
        });

});
</script>

index.html

    <ons-navigator animation="slide" var="app.navi">
    <ons-page>
    /*/ content /*/
     <div id="userid"></div>
    </ons-page>
    </ons-navigator>

    <ons-template id="page2.html">
    <ons-page>
    /*/ content /*/
    <div id="acc_nbr"></div>
    </ons-page>
    </ons-template>

解决方案

Try adding this to your <script> section

$(document.body).on("pageinit","#page2.html", function() {
   // call that same ajax function
}

这篇关于如何留住JSON对象在onsenui多个插件,模板页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆