2

I have a simple javascript App, which gives out some information of BLEs.

Everything is working fine, but I have some problems with the JQuery Mobile Library.

I want the whole App in simple JQuery Data-Theme="b". Since the List-View is created dynamically through the addDevice function, it's not working with the JQuery. When I try it without the .append() command, it's working - so there is no problem with my JQuery Mobile Library. I also tried to add the data-theme attribute with the .append() command, with this:

    $devices.attr("data-theme" , "b");

but still not working..

Below are the out-takes from my html and javascript files.

html:

 <ul data-role="listview" class="devices" id="myresult" data-theme="b"></ul>
    <div data-role="content" id="result">
         <script type="text/template" id="device">   
            <ul data-role="listview" data-theme="b">
                <li data-address="{0}">
                    <h2>{1}</h2>
                    <h2>RSSI: {2}</h2>
                </li> 
            </ul>
        </script>   
    </div>

javascript:

function addDevice(address, name, rssi)
{
    for (var i = 1; i<50; i++)
    {
        var $devices = $(".devices");

        var $check = $devices.find("li[data-address='{0}']".format(address));

        if ($check.length > 0)
            {
                return;
            }
        var template = $("#device").text().format(address, name, rssi);

        $devices.append(template);
        window.setTimeout(50000);

        if (rssi < -90){    
        alert(name + " loses proximity");
        }
    }       
}

Maybe someone has an idea what's wrong with my code..

1 Answers1

1

I don't know what you want to achieve here. But you can dynamically append data in listview in Jquery Mobile using below code.

HTML:

<div data-role="content">
<ul data-role="listview" class="devices" id="myresult" data-theme="b"> 
</ul>
</div>

Javascript : In very simple and easy way.

function addDevice(address,name,rssi) {

var result ="";

for (int i = 1; i<50;i++) { result += '<li>'+address+'<h2> '+name+'</h2>' result +='<h2> RSSI : '+rssi+'</h2>' result +='</li>' } $('#myresult').append(result); }

As well you can check below link for dynamic list using jquery mobile. http://jsfiddle.net/Gajotres/8uac7/