0

I'm having a hard time to structure the list location for items array in order to access name attribute in search.js Below is the nested JSON structure:

{
  menus: [
    {
     name: "Summer ",
     url: "/menus/2",
     items: [
       {
         name: "man o man", //this is what I'm trying to access
         url: "/menus/2/items/7"
       }
     ]
  ]
}

So far I've tried in search.js:

document.addEventListener("turbolinks:load", function() {
  $input = $("[data-behavior='autocomplete']")

  var options = {
     getValue: "name",
     url: function(phrase) {
       data = "/search.json?q=" + phrase;
       return data;
     },
     categories: [
      {
        listLocation: "menus",
        header: "--<strong>Menus</strong>--",
      },
      {
        listLocation: "items", //this is where I'm having problem with 
        header: "--<strong>Items</strong>--",
      }
    ],
    list: {
       onChooseEvent: function() {
         var url = $input.getSelectedItemData().url
         $input.val("")
         Turbolinks.visit(url)
       }
    }
  }

  $input.easyAutocomplete(options)
})
Marvin
  • 11
  • 4

0 Answers0