小部件中的Durandal事件 [英] Durandal Event in widgets

查看:98
本文介绍了小部件中的Durandal事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我还有另一个DurandalJS问题. 所以我有一些小部件几乎都是自包含的.它们根据当前用户是否登录(例如,是否登录)呈现或隐藏自己.我有一个显示当前用户名的小部件,另一个显示了当前用户的设置的小部件. 当前用户是存储在本地存储中的值,因此每个人基本上都知道要从那里获取它并尽自己的本分.

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.

我所有的小部件(包括外壳)都需要此安全模块,并且它们都处理事件. 现在我知道该事件正在运行,因为调用了Shell的事件处理程序,但小部件甚至认为它们都显示在Shell中也从未看到过该事件.

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.

谢谢

推荐答案

问题是我从小部件返回了单例.我不知道有什么区别,但是当我返回单身人士时,我从未得到任何事件. Durandal希望小部件是构造函数,以便它可以实例化同一类型的多个小部件请参见此处

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是一个函数导出模块,它将用作所有小部件代码的位置.小部件基础结构将通过composition模块将其绑定到view.html.

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.

这篇关于小部件中的Durandal事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆