2014-10-06 70 views
0

我想知道用最简单的方法替换所有警报('错误...')的最佳方式。用Kendo通知替换JavaScript警报

这样我就可以做

myKendoAlert( '我的信息',资讯);而且我不必为每个页面添加特定的html div或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文件与功能我可以对所有页面使用。与,信息,错误,成功...(并成功清除)

+2

看到了这一点? http://blogs.telerik.com/kendoui/posts/13-11-12/how-to-do-javascript-alerts-without-being-a-jerk – chris 2014-10-07 08:05:06

+0

这是一个kendo窗口,不是通知,但我会我可以在那里使用一些东西,谢谢。 – 2014-10-07 21:44:15

回答

1

只需要添加一个方法到你的名字空间来做到这一点,并从你需要的地方调用它。

这是一个与我所做的类似的示例,在我的应用程序(我使用toastr,但方法相同)的JavaScript命名空间的顶层放置了两个方法showSuccess和showError。

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

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

+0

但是用kendo通知而不是toastr做最好的方法是什么?如何在没有为我的页面放置特定的div的情况下弹出它。 – 2014-10-07 20:04:12

+0

只需取出toastr电话,并创建一个kendo通知。 http://jsbin.com/novena/2/edit – 2014-10-08 14:27:26

0
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); 
}