Question

enter image description here

a have a lot of articles under categories. like 3 articles under same title, after that 2 articles under same title and so one.

i'm building it with JQuery, and ist ok so. getting out each entry in array. Output looks like:

1. Innere Unruhe, Angstgef�hle, Schlafst�rungen - ein Problem vieler Menschen
1. Innere Unruhe, Angstgef�hle, Schlafst�rungen - ein Problem vieler Menschen
1. Innere Unruhe, Angstgef�hle, Schlafst�rungen - ein Problem vieler Menschen
2. Gesunde und krankhafte Angst
2. Gesunde und krankhafte Angst

but i need it like this:

1. Innere Unruhe, Angstgef�hle, Schlafst�rungen - ein Problem vieler Menschen
2. Gesunde und krankhafte Angst

here is my jQuery:

var contentarticles = articles.contentarticles;
for (var i = 0; i < contentarticles.length; i++) {
    var article = contentarticles[i];
    var $articlesOutput = $([
        '<li><a href="/id=', article.id, '/step=', i+1, '">',
        article.title,
        '</li>'
    ].join(""));
    $("#articlesOutput").append($articlesOutput);
}

Please help!

Was it helpful?

Solution

This simple modification should avoid duplicates:

var contentarticles = articles.contentarticles,
    article,
    $out = $("#articlesOutput");
for (var i = 0; i < contentarticles.length; i++) {
    if (!article || article.title != contentarticles[i].title) {
        article = contentarticles[i];
        var articlesOutput = [
            '<li><a href="/id=', article.id, '/step=', i+1, '">',
            article.title,
            '</li>'
        ].join("");
        $out.append(articlesOutput);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top