用剑道通知取代javascript警报



我想知道用剑道通知替换所有警报("error…")的最佳方法,这是最简单的方法。

所以我可以做

myKendoAlert("我的消息",信息);并且我不必在每个页面上添加特定的htmldiv或span占位符。

目前我正在做一些类似的事情:

var popupNotification = $("#popupNotification").kendoNotification({
    position: {
        pinned: false,
        bottom: 100,
        right: 100
    },
    templates: [{
        type: "info",
        template: "<div>Test : #= myMessage #</div>"
    }],
    autoHideAfter: 0,
    stacking: "up"
}).data("kendoNotification");

但我需要把它放在一个通用的javascript文件中,该文件具有一个可以在所有页面上使用的函数。有,信息,错误,成功。。。(成功后清除)

只需在命名空间中添加一个方法即可实现这一点,并在需要的地方调用它。

这里有一个与我所做的类似的示例,将showSuccess和showError两个方法放在我的应用程序的javascript命名空间的顶层(我使用toast,但方法相同)。

我在窗口对象上有我的应用程序对象,有两个方法可以从任何地方调用。

http://jsbin.com/novena/1/edit

var notificationWidget = null;
function alert(message, type) {
    if (notificationWidget == null) {
    notificationWidget = $("#notification").kendoNotification({
        button: true,
        hideOnClick: true,
        //appendTo: "#container",
        //width: "30em",
        position: {
            pinned: true,
            top: "5em",
            left: null,
            bottom: null,
            right: 10
        },
        autoHideAfter: 8000
    }).data("kendoNotification");
}
    notificationWidget.show(message, type);
}

最新更新