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;
});