Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi
I have a script which basically selects the listbox in qlikview using Qlikview Ajax API and its continously running in a loop .
function Demo () {
Qv.AddExtension("ET-HelloWorld",
function () {
var _this=this;
// Set the extension object's inner Html
var doc=Qv.GetCurrentDocument();
this.Element.innerHTML = 'Save Selection';
var lb;
var jsFiles = [];
jsFiles.push('Extensions/Objects/ET-HelloWorld/lib/js/jquery.js');
Qv.LoadExtensionScripts(jsFiles, function () {
initQlikView(doc);
});
function initQlikView(doc) | ||||
{ | ||||
doc.GetAllObjects(function(objects) { | ||||
for (var i = 0; i < objects.length; i++) { | ||||
if (objects.type == 'List Box' && objects.id.match(/LB15/)) { |
var object =doc.GetObject(objects.id,function(){object.Data.SelectTexts("GA")});
} | ||||
}}); | ||||
} |
The output i get is continue alert box . I think the SelectTexts function again triggers the execution of the entire script and ends up as unending loop of function calling itself
Any ideas how implement the code to avoid circular callback ?
I've run into the same problem and kinda solved it by doing this.
var attached = false; // <-- outside the closure so that is doesnt get set when extension re-renders
if(!attached) {
attached = true;
var obj = doc.GetObject("LB02");
obj.callbackFn = function() {
var arr = ["TextValue"];
this.Data.SelectTexts(arr);
this.callbackFn = null;
}
}
It's not very elegant but seems to be working.