Select to view content in your preferred language

Javascript Search Widget (searchWidget.sources.push(sources))

3417
7
Jump to solution
05-23-2016 04:49 AM
SachinTiwari
Emerging Contributor

Hi,

     Just would like to confirm that, the search widget is pushing search layer at right level or not ?

because when i try to push a source then it gets added in wrong heirchical level.

var sources = [ { declare only one source } ]

// Add to source(s)
var searchWidget = new Search();
searchWidget.sources.push(sources); 
//new source
searchWidget.startup();

Then it shows heirchy like

items

     [0]

     [1]

          [0] and here is my source (underneath of [1][0])

I believe my source should be at [1] level of heirchy.

Please correct me if i am missing anything.

0 Kudos
1 Solution

Accepted Solutions
FC_Basson
MVP Alum

You are adding an array and not a source object.  Just remove the square brackets from your sources variable declaration.

View solution in original post

7 Replies
SachinTiwari
Emerging Contributor

searchwidget.png

0 Kudos
SachinTiwari
Emerging Contributor

if the heirchical level is correct then why i m not able to search on added (pushed) sources, whereas when i add the same source at the constructor level of Search() widget then it works perfectly.

0 Kudos
FC_Basson
MVP Alum

You are adding an array and not a source object.  Just remove the square brackets from your sources variable declaration.

SachinTiwari
Emerging Contributor

Thanks for the solution. (Heirchical level is solved by your response but search issue is still remains)

But the issue remains the same, when i tried to push a source then it won't search on pushed source. and when i assign the same code in the constructor of search() widget then it searches perfectly. I think i am lacking somewhere, let me check once again. or if you have any other clue on that ?

0 Kudos
FC_Basson
MVP Alum

I've constructed my own search sources like this in the past:

sources = searchWidget.get("sources");
sources.push(newsourceobject); //push for adding at the end of the list and unshift to add at the front of the list
searchWidget.set("sources", sources);
searchWidget.startup();
SachinTiwari
Emerging Contributor

other way around 🙂

0 Kudos
FC_Basson
MVP Alum

You mean the push/unshift? I'm pretty sure. JavaScript Array unshift() Method

0 Kudos