Ash
Ash

Reputation: 237

Dynamic Listview and Button in Jquery Mobile

Im following a example where they mentioned Ive to insert

$('[data-role="button"]').button();

to add the button dynamically in a proper way. But it shows

button.(..) is not a function, error.

HTML

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

        <div data-role=header>

            <h1>Home</h1>

        </div>

        <div data-role="content" style="padding: 15px">

            <ul data-role="listview" id="listview" data-inset="true" data-filter="true">
                <li data-role="list-divider" id="divider">Available Devices</li>

            </ul>


        </div>
        <div data-role="footer" data-position="fixed" id="footer">
            <h3>Footer</h3>
        </div>
    </div>

Javascript function:

 function displayFeeds(items){
        var ul = $('#listview');
        for (var i = 0; i < items.length; i++) {
             var li = $('<li/>').html(items[i].DeviceNames);
             li.append($('<li/>').html(items[i].DeviceQuantity));



            li .append('<a data-role="button" data-theme="b" data-icon="plus" data-iconpos="right">Save</a>');
             // Enhance new button element
            li.append($('<hr>')); 
             ul.append(li); 

       }
        $('[data-role="button"]').button();
    }

What should I do here Or what am I doing wrong?

Upvotes: 0

Views: 977

Answers (1)

Bhoomika Brahmbhatt
Bhoomika Brahmbhatt

Reputation: 7415

I had same problem.

Don't put $('[data-role="button"]').button();

Put ul.parent().trigger( 'create' ); at end of your for loop.

Upvotes: 1

Related Questions