Sitecore 8 Speak UI QueryDataSource in Javascript

175 Views Asked by At

I am trying to access QueryDatasource results in Javascript. Everything is setup correctly. I get the items by using

var destData = this.regionQueryDatasource.get("items");

My issue is that,

  1. I want to get those items on page load. I put this code inside initialize() then it doesn't return anything. If I call it in some button click function, then it returns data.

      initialized: function () {
      var destData = this.regionQueryDatasource.get("items");},
    
  2. I want the querying to happen in synchronous manner. Sometimes, the items are returned as empty. I want to wait till the items are loaded.

Any help would be great. Thanks in advance!

1

There are 1 best solutions below

0
Komainu85 On

Have you tried refreshing the DataSource before calling Get items?

E.g

 this.regionQueryDatasource.refresh()

Then you can check viewModel.hasItems()

Id recommend using this.regionQueryDatasource.viewModel.items() rather than this.regionQueryDatasource.get("items");