0

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.

James
  • 1,827
  • 5
  • 39
  • 69

1 Answers1

3

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);
Kyeotic
  • 19,697
  • 10
  • 71
  • 128
  • What if i dont want to pass data returning from datacontext? I tried using function but it still not working. – James Feb 24 '14 at 07:56
  • What does `getData()` do then? Set something that will be collected by the event listener? If that is the case, using a function should work, and you have another issue if it isn't. Unfortunately I can't say what that is without more information. – Kyeotic Feb 24 '14 at 18:46
  • getData just return some data from webapi. actually i have 2 app.trigger like this return (datacontext.getData("Test, testData)) .then(function() { app.trigger('FireEvent', dataObsArray); app.trigger('FireEvent1',testData); }) .fail(queryFailed); – James Feb 24 '14 at 19:49
  • If `getData()` returns the `dataObsArray`, then it needs to be the parameter to the `then()` handler. `datacontext.getData("Test, testData)) .then(function(dataObsArray) { app.trigger('FireEvent', dataObsArray)` – Kyeotic Feb 24 '14 at 21:09
  • getData returns data and that i pass to obs array called dataObsArray. I get some data in testData from other way and that i want to pass. Hence i tried to use 2 app.trigger statement, one will get data from getData method and other will just get data from other obs array. – James Feb 24 '14 at 21:16
  • You're going to need to post your code, I'm not sure I understand. – Kyeotic Feb 24 '14 at 21:37