2012-08-11 64 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文件。