Durandal Event in widgets

丶灬走出姿态 提交于 2019-12-25 04:26:29

问题


So I have yet another DurandalJS question. So I have a few widgets that are pretty much self contained. They render or hide themselves depending on whether the current user is logged in or not e.g. I have a widget that displays the current users name, and another one that displays some setting for the current user. The 'current user is a value stored in local storage so everyone basically knows to get it from there and do their bit.

I have a security module which triggers an event on itself when a user is logged in and when a user is logged out.

All my widgets including shell require this security module and they all handle the event. Now I know the event is working because shell's event handler gets called but the widgets never see the event even thought they are displayed in shell.

However, if I do a hard refresh of the page (whether the user is logged in or out), all the widgets render properly so I know the widgets know what to do. Am I doing this wrong? If yes how best do I go about it.

Thanks


回答1:


The problem was that I was returning singletons from my widgets. I have no idea what the difference was but I never got the events when I returned singletons. Durandal expects widgets to be constructor functions so that it can instantiate multiple widgets of the same kind see here

viewmodel.js is a function exported module that will serve as a location for all your widget's code. It will be bound to view.html by the widget infrastructure via the composition module.



来源:https://stackoverflow.com/questions/19681076/durandal-event-in-widgets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!