Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:27:01+00:00 2026-06-14T10:27:01+00:00

I try to dynamically generate a listview in jQuery. This works perfectly for the

  • 0

I try to dynamically generate a listview in jQuery. This works perfectly for the whole list, but now I need to filter/search/reduce my initial data:

var rezepte = [
{ "name" : "Eierkopf" , "zutaten" : ["Eier", "Zucker"] , "zubereitung" : "alles schön mischen." },
{ "name" : "Käseschnitte" , "zutaten" : ["Käse", "Brot", "Paprika"] , "zubereitung" : "Käse drauf und in den Ofen" },
{ "nme" : "Gemüse-Auflauf" , "zutaten" : ["Lauch"] , "zubereitung" : "1. schneiden 2. Kochen 3. essen" }
];

I would like to filter/search “recipe” by a searcharray like var searcharray = ["Zucker", "Paprika"] resulting in:

var result = [
{ "name" : "Eierkopf" , "zutaten" : ["Eier", "Zucker"] , "zubereitung" : "alles schön mischen." },
{ "name" : "Käseschnitte" , "Zutaten" : ["Käse", "Brot", "Paprika"] , "zubereitung" : "Käse drauf und in den Ofen" }];

I have tried a lot of things within the for loop: filter, map, push – but all without sucess always resuling in undefined objects.

I am also not sure what syntax my recipe Array should be: there must be the possibility of variable amount of “ingredients”.

Any help and hint would be most appreciated.

Thanks a lot,
Andi

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:27:02+00:00Added an answer on June 14, 2026 at 10:27 am
    var rezepte = [
    { "name" : "Eierkopf" , "zutaten" : ["Eier", "Zucker"] , "zubereitung" : "alles schön mischen." },
    { "name" : "Käseschnitte" , "zutaten" : ["Käse", "Brot", "Paprika"] , "zubereitung" : "Käse drauf und in den Ofen" },
    { "nme" : "Gemüse-Auflauf" , "zutaten" : ["Lauch"] , "zubereitung" : "1. schneiden 2. Kochen 3. essen" }
    ];
    
    function search() {
        var search = $("#searchfield").val(); // returns string
        var searcharray = search.split(',');
        if (searcharray == "") {
            check = $.isArray(searcharray);
            alert(check); // true
            return rezepte;
        } else { 
            var result = [];
            alert("till here fine");
            result = $.grep(rezepte, function(rezept) {
                for (var i=0; i<searcharray.length; i++) {
                    if ($.inArray(searcharray[i], rezept.zutaten) != -1)
                        return true;
                } 
                 return false;
            });
        }
        console.log(result);
        return result;  
    }
    $(function(){
         $("#search").click(search);
    })
    

    I have it working with this code. See demo: http://jsfiddle.net/VcZtE/1/ (results could be seen in browser console). The only difference from your code is here: if ($.inArray(searcharray[i], rezept.zutaten) != -1). According to docs for inArray needle should be a first parameter and array to search in – second. And you have it in opposite way: array is passed as a first param and needle (value to search for) as a second.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my program I generate classes dynamically but when I try: String[] args =
I started with https://developers.google.com/maps/articles/phpsqlajax_v3 and am using https://developers.google.com/maps/articles/phpsqlsearch_v3 to try to dynamically filter the
Im try to create a spinner dynamically on press of a button. this is
I try to generate a table dynamically, based on an user input. The idea
Morning people. How to make my javascript or jquery works in dynamically generated content.
No matter what I seem to try and do regarding this listview and trying
got anyways to dynamically generate JComponent like JTextField, JCombobox? What i try is work..,
I dynamically generate some markup and inject it into the DOM like this: content+='<td><a
I'm using a stringstream to generate dynamically, the name of the files I need
I've had this problem many times: I create HTML dynamically via jQuery, and in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.