canjs

How to trigger an event with newVal in CanJs


I am stuck while trying to trigger a CanJs event with newVal.I have a change event like below:

"{ApplicationShell.AppState.processState.modelExecution} change": function (model, ev, attr, how, newVal, oldVal) {
  if (newVal === "Something"){
  }
}

So here i have to trigger this event. I can trigger this event using below code:

can.trigger(ApplicationShell.AppState.processState.modelExecution,"change") 

But i couldn't pass a value to newVal of the changed event. I tried to pass like below:

can.trigger(Sentrana.ApplicationShell.AppState.processState.modelExecution,"change","abcd"); 

But this "abcd" is passed to the attr of the event method not in the newVal parameter.


So is there any way to pass value to the newVal using can trigger?


Solution

  • Yeah we can send value to the newVal using can.trigger().

    can.trigger(ApplicationShell.AppState.processState.modelExecution,"change",["a","b", "c", "d"])
    

    Now the values will go the trigger event like below:

    "a" -> attr
    "b" -> how
    "c" -> newVal
    "d" -> oldVal