Question

I am using durandal to pass messages between view models. So i used below code to send message

 return (datacontext.getData("Test, testData))
                .then(app.trigger('FireEvent', `dataObsArray`))
                .fail(queryFailed);

Then i use below code to retrieve message

 app.on('FireEvent').then(function (data) {
            testObsArray(data);
        });

But when i put breakpoint in the app.on on this line testObsArray(data); it doesnt stop there. The debugger stops on line app.on('FireEvent').then(function (data)

I dont get data. Why is it so? When i pass data to dataObsArray , there are 10 records.

I am not sure why i am not getting any data. Where i am wrong? I am really new to Durandal so extremely sorry if i am not able to explain this properly and do let me know if you need more clarification.

Was it helpful?

Solution

Your problem is here;

.then(app.trigger('FireEvent', `dataObsArray`))

The way that will resolve is to call app.trigger, get the result, and pass that as the next step in the chain to then(), which is unlikely to be what you want. You need to wrap that in an anonymous function so that then() can call it after the dataContext call.

return (datacontext.getData("Test, testData))
                .then(function(data) {
                    app.trigger('FireEvent', data?) //This depends on what getData returns
                })
                .fail(queryFailed);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top