2012-08-11 19 views
14

我有以下的javascript代码:的Javascript插件Noty给出错误

function delete_draft(id, name) { 
    var text = 'Are you sure you want to delete "' + name + '"?'; 
    alert(id + name) 
    var noty = noty({ 
     text: text, 
     buttons: [ 
     {addClass: 'btn btn-primary', text: 'Yes', onClick: function($noty) { 

      // this = button element 
      // $noty = $noty element 

      $noty.close(); 
      $.post('/ajax/drafts/delete', {id:id}, function(data) { 
       document.location.reload(true); 
      }); 
     } 
     }, 
     {addClass: 'btn btn-danger', text: 'Cancel', onClick: function($noty) { 
      $noty.close(); 
     } 
     } 
    ]}); 
} 

当我从领事delete_draft(6, "this is it")运行我得到这个错误

TypeError: undefined is not a function 
arguments: Array[1] 
get message: function() { [native code] } 
get stack: function() { [native code] } 
set message: function() { [native code] } 
set stack: function() { [native code] } 
type: "called_non_callable" 
__proto__: Error 

我该如何解决这个问题? Noty的网站是http://needim.github.com/noty/ 如果你认为它应该工作,评论。

+0

'noty'是什么?在代码中'var noty = noty' noty as function as undefined。可能是你需要''var noty = function('? – Vsevolod 2012-08-11 21:41:09

+0

@Vsevolod这就是为什么我把一个链接到底部的noty站点 – 2012-08-12 00:07:00

+0

@“Mike G”我无法打开你的链接:-(你如何插入笔记。 js in your html? – Vsevolod 2012-08-12 00:25:36

回答

25

我刚刚遇到过这个问题。原因是因为变量名称noty与导出的函数名称noty相同。

var n = noty({text: 'testing 123'}); 

只需更改变量名就可以修复它。

+1

非常感谢这个! – 2013-02-21 13:06:22

+0

谢谢,救了我几分钟:) – 2013-03-15 18:32:34

+0

在noty的主页中,他们把样本var noty = noty({...非常感谢!!!! – 2013-07-24 17:30:47

4

除了重命名变量,请确保您包含布局js文件。默认是顶部,所以如果没有在选项中指定,您需要包含noty/layouts/top.js。如果您指定任何其他布局,请包含适当的布局js文件。