获取tokenInput结果中的自定义字段

时间:2015-11-02 07:27:25

标签: jquery jquery-plugins jquery-tokeninput

我使用过jquery插件" tokenInput"形成标记的搜索结果。

我的代码如下:

<html>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="C:/Users/admin/Downloads/loopj-jquery-tokeninput-201d2d1/src/jquery.tokeninput.js"></script>
<link rel="stylesheet" type="text/css" href="C:/Users/admin/Downloads/loopj-jquery-tokeninput-201d2d1/styles/token-input.css" />
<link rel="stylesheet" type="text/css" href="C:/Users/admin/Downloads/loopj-jquery-tokeninput-201d2d1/styles/token-input-facebook.css" />


<body>

    <h2 id="theme">Tabs Horizontal</h2>
    <div>
        <input type="text" id="demo-input-facebook-theme" name="demo2" />
        <button type='button' class='btn btn-primary' onclick='Dashboard.search.searchResult();'> SUBMIT</button>
        <script type="text/javascript">
        $(document).ready(function() {
            var flat_obj = [{_id: 7, name: "Ruby"},
                {_id: 11, name: "Python"},
                {_id: 13, name: "JavaScript"},
                {_id: 17, name: "ActionScript"},
                {_id: 19, name: "Scheme"},
                {_id: 23, name: "Lisp"},
                {_id: 29, name: "C#"},
                {_id: 31, name: "Fortran"},
                {_id: 37, name: "Visual Basic"},
                {_id: 41, name: "C"},
                {_id: 43, name: "C++"},
                {_id: 47, name: "Java"}];
            $("#demo-input-facebook-theme").tokenInput(flat_obj, {
                theme: "facebook",
                tokenValue: "_id"
            });
        });
        </script>
    </div>

</body>
</html>

Dashboard.search.searchResult

searchResult : function(){
            $("#demo-input-facebook-theme").tokenInput("get");
            console.log("value : " ,$("#demo-input-facebook-theme").tokenInput("get"));
        }

当我打印输出时,结果如下:

id: undefined
name: "Lisp"

我需要&#34; _id&#34;要包含在搜索结果中而不是ID中。 我尝试过tokenValue:&#34; _id&#34;,但它没有用..

需要帮助.... !!

0 个答案:

没有答案