简体   繁体   中英

How to get access to Current view model methods from Shell.js

I have a button in shell.html, on click of that button I need to post the current view model.

I can determine the current view model's Module Id, but how can I get a reference to it so that I can invoke its methods from Shell.js

For eg, if my current view model has a method called "SubmitApplication" I would like to call or trigger this method from Shell.js on click of the button in Shell.html

Please help.

Thanks

Consider using Durandal's event system for cross module communication. http://durandaljs.com/documentation/Leveraging-Publish-Subscribe.html

By default app has event capabilities included, which would allow you to do something along the following line:

shell.js

submitOnClick: function(){
    app.trigger('application:submit', payload);
}

viewmodel

app.on('application:submit').then(function(payload){
    //do something with payload
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM