Create Jquery Mobile Navbar dynamically from JSON data

I’m trying to dynamically create a navbar from data i fetch from a web api serving json data. Here’s the code: https://gist.github.com/2962277
If i use:

directly in html code works fine, but this is not what im looking for. I want to be able to create the list elements from the data in the like the code in gist show. Anyone could point me in the right direction?

Once you have concocted your HTML for the navbar widget, you simply call .trigger('create')
on the widget:

var myNavbar = $('');
$('#some-container').append(myNavbar).trigger('create');

Here is a demo: http://jsfiddle.net/Jde95/

This will trigger jQuery Mobile to initialize the widget.

For Example:

var url = "http://23.21.128.153:3000/regions.json";var jsonresults;
$.getJSON(url,function(data){
    var output = [];
    $.each(jsonresults, function(i,v){
        output.push('
  • ' + jsonresults[i].name + '
  • '); }); $('#main-content').append('
    ' + output.join('') + '
    ').trigger('create'); });

    Notice how I concocted the HTML, and used the .append()
    function.

    Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

    阅读提示:酷辣虫无法对本内容的真实性提供任何保证,请自行验证并承担相关的风险与后果!
    本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
    酷辣虫 » 移动开发 » Create Jquery Mobile Navbar dynamically from JSON data

    喜欢 (0)or分享给?

    专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

    使用声明 | 英豪名录