0

I have the following HTML code. It is a popup with a collapsible listitems inside:

<div data-role="popup" id="wavelistPopup" class="ui-content">
    <div id="wavlistContainer" data-role="collapsible-set" data-theme="c" data-content-theme="c" data-collapsed-icon="arrow-r" data-expanded-icon="arrow-d" style="margin:0; width:250px;">
        <div data-role="collapsible" data-inset="false">
            <h2>Wave1</h2>
            <ul data-role="listview">
                <li>Entfernung: </li>
                <li>Von Autor:</li>
                <li>Schwierigkeit:</li>
                <li>Beschreibung:</li>
                <li><a data-rel="dialog">Erfahrungsberichte</a></li>
                <li><a data-rel="dialog">Wissenswertes</a></li>
                <li><a data-rel="dialog">&Auml;hnliche Waves</a></li>
            </ul>
            <button>Sync</button>
            <button>L&ouml;schen</button>
        </div><!-- /collapsible -->

    </div><!-- /collapsible set -->
</div><!-- /popup -->

Now I want to add another collapsible to the wavlistcontainer with the following code:. To do that, I first make a ajax call and work in the callback function.

function populateWaveList(){
    console.log("populateWaveList");
    requestWavesInArea(position.position.coords.latitude, position.position.coords.longitude,  
            position.position.coords.latitude+5, position.position.coords.longitude+5, 10, 
            function(waves){ //after AJAX call
            console.log(waves);
                for(var wavei in waves){ // for every element to add
                    var content = "";
                    var wave = waves[wavei];
                    console.log(wave);
                    var content =+ jQuery('somestring';     '<div data-role="collapsible" data-inset="false">'+
                                '<h2>'+wave.name+'</h2>'+
                                '<ul data-role="listView">'+    
                                        '<li>Entfernung von Autor: '+'...'+'</li>'+
                                        '<li>Autor: '+wave.creatorname+'</li>'+
                                        '<li>Beschreibung: '+wave.description+'</li>'+
                                        '<li>Umfang: '+'...'+'</li>'+
                                        '<li>Terrain: '+wave.terrainType+'</li>'+
                                        '<li>Autor: '+wave.creatorname+'</li>'+
                                        '<li>Schwierigkeit: '+wave.difficulty+'</li>'+
                                        '<li>ID: '+wave.waveId+'</li>'+
                                        '<li>Datum: '+wave.created+'</li>'+
                                    '</ul>'+
                                    '<button disabled="disabled">Sync</button>'+
                                    '<button disabled="disabled">L&ouml;schen</button>'+
                                '</div>');
                    console.log(content); // returns 'false'
                    $('#wavelistContainer').append(content);
                }
                $('#wavelistPopup').popup('open', { x : 460, y : 180 });
    });
}

When I print the content, i get false which greately confuses me. Can anyone help me with this please?

Thank you

2
  • 2
    If you change the question using the answers, they get irrelevant... This is not how you should use SO... Commented Oct 17, 2012 at 15:47
  • you are right, I implemented the mistakes again :D Commented Oct 17, 2012 at 16:01

2 Answers 2

1

Two problems :

  • you're using =+ instead of +=
  • you convert to soon the html to a jquery object

This line :

​var content =+ 'somestring';

is the same as

​var content = 0 + 'somestring';

and so produces NaN.

Instead of

content =+  jQuery('<div data-role="collapsible" data-inset="false">'+

do

content +=  '<div data-role="collapsible" data-inset="false">'+

Note that you should also, for better performances, build only one content string and add it only once (declare it before the loop, and append it after the loop).

Sign up to request clarification or add additional context in comments.

4 Comments

I don't think you can get false if you build it with var content = ""; content += 'somestring';. Check the code you run.
I edited my code accordingly. Now I have the problem that the created elements are not collapsible. they are displayed directly.
You don't even show the code responsible of the collapse... How could I fix it ?
what do you mean. I tried to recreate the code above dynamically.
1

You have problem your code

    content =+  jQuery('<div data-role="collapsible" data-inset="false">'+
--------------^-----^
                                    '<h2>'+wave.name+'</h2>'+
                                    '<ul data-role="listView"'>+    
--------------------------------------------------------------^

should be

content +='<div data-role="collapsible" data-inset="false">'+
                                    '<h2>'+wave.name+'</h2>'+
                                    '<ul data-role="listView">'+   

4 Comments

I edited my code accordingly. Now I have the problem that the created elements are not collapsible. they are displayed directly.
@MJB the code looks fine...Hard to figure out what's the problem..Check that all div are closing properly..?
there is only one div, the div that closes the collapsible, and it's closed.
@MJB i have no idea about that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.