2014-10-21 30 views
0

我試圖查看不同的來源,也看到了發佈類似問題的論壇,但它並沒有幫我解決im面臨的問題。 我有一個文本輸入提交給我添加一個彈出窗口來顯示數據庫中的類似名稱列表。 inout字段檢查驗證,看看輸入的名稱是否是唯一的,如果不是,則顯示數據庫中可用的類似名稱,可以重新使用。 這裏是酥料餅的片段:如何使用popover添加內容ajax boostrap

$("#account_name_create").popover({ 
       title: 'Twitter Bootstrap Popover', 
       content: function (process) { 
        this.accountCollection = new ipiadmin.collections.AccountCollection(); 
        var newName = $("#new-account-form #account_name_create").val(); 
        var userFilter = "accountName~'" + newName + "'"; 
        this.accountCollection.fetch({ 
        data: { "f": userFilter, 
         "sortby": null, 
         "type":"ipi", 
         "pageno":0, 
         "pagesize":2, 
         "reversesort" : true 
        }, 
        cache: false, 
        success: function(model, response, options) { 
         var states = []; 
         map = {}; 
         $.each(model.aDataSet, function (i, state) { 
          map[state.accountName] = state; 
          states.push(state.accountName); 
         }); 
         process(states); //gives an error saying 'undefined is not a function (says process is undefined)' 
        }, 
        error: function(model, response, options) { 
        console.log('error'); 
        } 
       }); 

      }, 
     }); 

下面是HTML:

<input type="text" id="account_name_create" name="account_name" class="" size="40" /> 

我不知道怎麼樣,爲什麼它說,「過程」爲未定義。也不知道這是否是在popover中顯示數據的正確方法。 任何想法??

謝謝!

回答

0

process在成功函數中沒有範圍,只在內容函數中。如果你想在成功函數中調用process函數,你可以在jQuery調用之外的地方定義它。

+0

想怎麼樣?你能幫我從上面的代碼顯示嗎? – user1234 2014-10-22 00:00:48

+0

縮進讓我失望。那麼,定義的'process'參數在哪裏,你傳遞給了'content'函數? – smoothgrips 2014-10-22 00:27:02

+0

對於身份驗證..im在內容中傳遞過程參數:function(){}如此理想,它仍然在成功範圍內:function {},我認爲 – user1234 2014-10-22 03:29:28