2013-01-24 141 views
1

我正在使用jQuery Tokeninput來顯示用戶的電子郵件,其實我正在嘗試邀請用戶。當我點擊輸入文字並輸入一些電子郵件時,即使該電子郵件存在,也總是說不出結果。JQuery TokenInput不顯示搜索結果

我的JS是

<script type="text/javascript"> 
    $(document).ready(function() { 
    var url = "http://localhost:9000/api/customers" 
     $("#members").tokenInput(url, { 
      theme: "facebook" 
     }); 
    }); 
    </script> 

我的控制器動作

public static Result apiCustomers(){ 
    List<Customer> customerList = Model.coll(Customer.class).find().toArray(); 
    List<String> emails = new ArrayList<String>(); 

    for(Customer c : customerList){ 
     emails.add(c.email); 
    } 

    ObjectNode result = Json.newObject(); 
    result.put("emails", Json.toJson(emails));  
    return ok(result); 
    } 

當我輸入的東西,它調用apiCustomer行動的文本輸入和響應看起來這是一個有效的JSON字符串

{"emails":["[email protected]","[email protected]","[email protected]","[email protected]"]} 

在此先感謝

回答

2

我還沒有使用Tokeninput插件,但它似乎是你不輸出正確的JSON。雖然您的操作正在生成有效的json字符串,但它不是插件所期望的json字符串。

有關正確的格式,請參閱Tokeninput documentation