Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8820663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:39:50+00:00 2026-06-14T05:39:50+00:00

My setup is jQuery Mobile (JQM), multi-page, JSON, and Handlebars.js. I have a list

  • 0

My setup is jQuery Mobile (JQM), multi-page, JSON, and Handlebars.js.

I have a list of items. Each item links to a full page description.

<div data-role="page" id="document-library">

<div data-role="content">

    <ul>
    <div id="handlebarsDocuments">This will get replaced by handlebars.js</div>
    <script id="TemplateDocuments" type="text/x-handlebars-template">

        {{#documents}}
            <li style="float:left;padding:10px 0;width:100%;">
                <a href="#documentID{{documentID}}" data-transition="slide">
                    <strong>{{documentName}}</strong>
                </a>
            </li>
        {{/documents}}

    </script>
    </ul>

</div>

The URL changes to localhost/index.html#documentID20. Great, the links work.

Problem is, I can’t get the page to load the data specific to documentID20. JQM doesn’t initiate JavaScript if it’s sitting outside the data-role=”page” div. Plus, it’s multi-page so I’m thinking the data needs to be there before I click the link.

When I wrap handlebars around data-role=”page” it does not work.

<div id="handlebarsDocView">This will get replaced by handlebars.js</div>
<script id="TemplateDocView" type="text/x-handlebars-template">
    {{#documents}}

         <div data-role="page" id="document{{documentID}}">

              <div data-role="content"> 
                   {{#each_when documents "documentID" "20"}}
                        {{documentName}}
                   {{/each_when}}
              </div>

         </div>

    {{/documents}}
</script>

The JSON file looks like…

{
"documents": [
    {
        "documentID": 20,
        "conversationID": 100,
        "documentName": "K1711EA1 Course",
        "timeStamp": "2012-10-09T12:51:50Z",
        "documentType": "documents"
    },
    {
        "documentID": 21,
        "coversationID": 100,
        "documentName": "K17E10CTEC Student",
        "timeStamp": "2012-10-09T07:51:50Z",
        "documentType": "pdf"
    }
]
}

This has been added to my handlebars.js file to get each_when working.

Handlebars.registerHelper('each_when', function(list, k, v, opts) {
console.log(arguments);
var i, result = '';
for(i = 0; i < list.length; ++i)
    if(list[i][k] == v)
        result = result + opts.fn(list[i]);
return result;
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:39:51+00:00Added an answer on June 14, 2026 at 5:39 am
    <!DOCTYPE html> 
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Client Portal</title>
    <link rel="stylesheet" href="stylesheets/styles.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
    <script src="js/jquery.mobile-1.2.0.js?v=6"></script>
    </head> 
    
    <body onload="init()">
    
    <script type="text/javascript" src="js/handlebars-1.0.rc.1.js"></script>
    
    
    <!-- Document Library -->
    
    <div data-role="page" id="document-library">
    
        <div data-role="content">
    
            <ul>
            <div id="handlebarsDocuments">This will get replaced by handlebars.js</div>
    
            <script id="TemplateDocuments" type="text/x-handlebars-template">
    
                {{#documents}}
                    <li style="float:left;padding:10px 0;width:100%;">
                        <a href="#documentID{{documentID}}" data-transition="slide">
                            <strong>{{documentName}}</strong>
                        </a>
                    </li>
                {{/documents}}
    
            </script>
            </ul>
    
    
    
        </div>
    
    
    </div>
    
    <!-- Document View-->
    
    <script id="Foo" type="text/x-handlebars-template">
    
        {{#documents}}
    
            <div data-role="page" id="documentID{{documentID}}">
    
                Document Name {{documentName}}<br/>
                Document ID: {{documentID}}<br/>
                Conversation ID: {{conversationID}}
    
            </div>
    
        {{/documents}}
    
    </script>
    
    
    <script>
    // Handlebar
    var xhr;
    
            function init() {
    
                xhr = new XMLHttpRequest();
                xhr.onreadystatechange = xhr_onReadyStateChangeHandler;
                xhr.open("GET", "json/data.json");
                xhr.send(null);
            }
            function xhr_onReadyStateChangeHandler(evt) {
                if ((xhr.readyState === 4) && (xhr.status === 200)) {
                    var src = document.getElementById("TemplateDocuments").innerHTML;
    
                    var tmpl = Handlebars.compile(src);
                    var json = JSON.parse(xhr.responseText);
                    document.getElementById("handlebarsDocuments").innerHTML = tmpl(json);
    
    
                     src = $('#Foo').html();
                     tmpl = Handlebars.compile(src);
                    $('#document-library').after(tmpl(json));
    
                }
            }
    </script>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my current setup. I have two pages running on the jquery mobile
I'm trying to setup a page in Jquery Mobile and Coldfusion8. My Jquery Mobile
I have some onchange events setup in jQuery which are used to populate a
I have a datepicker control setup using the JQuery UI, I am also using
I have modified the dataTables filter input into a Jquery Mobile search filter ,
I have setup jQuery validation on form, The validation currently tests that the telephone
I am currently using jQuery Mobile on a project and have run into a
I have a very simple .NET MVC3 project set up using jquery mobile for
I'm trying to setup user authentification in Jquery Mobile/Coldfusion8. I'm using Coldfusion for just
I am developing a mobile application and I have a click function in jQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.