简体   繁体   English

在loopj-jquery-tokeninput中进行Facebook标记编辑(带有自动字段的Facebook标记下拉列表)

[英]edit in loopj-jquery-tokeninput for facebook tagging(Facebook tagging dropdown with auto field)

In this plugin every thing works fine only ,here json is in this format.I m very new to json ,so not able to understand the code. 在这个插件中,所有东西都只能正常工作,这里的json是这种格式。我对json非常陌生,因此无法理解代码。

[
            {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"}
        ]

But my json is something like this. 但是我的json是这样的。

 {
   "data": [
                {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"}
                ],
             "paging": {
      "next": "https://graph.facebook.com/100000454970389/friends?access_token=AAAAAAITEghMBAPkZAGQhUiXWSeaewhYZBsZBXIs37swq4Th90HHIwYfKgm12M9u20UR9iqpeTtXv477ZAvx5nD0NsbSMJWlpTCNSrvxZCTVHg6upTAZBmV&limit=5000&offset=5000&__after_id=100004141210773"
   }
}

this is the javascript where we are parsing the json. 这是我们解析json的javascript。

https://github.com/loopj/jquery-tokeninput/blob/master/src/jquery.tokeninput.js https://github.com/loopj/jquery-tokeninput/blob/master/src/jquery.tokeninput.js

thanks in advance. 提前致谢。

I Got the solution 我得到了解决

    <script type="text/javascript">
        $(document).ready(function() {

            var url = 'https://graph.facebook.com/me/friends?access_token=<?php echo $access_token ?>';
$.getJSON(url,function(json){
    beer = json.data;   
    console.log(beer);
    var myJSONText = JSON.stringify(beer);
            $("#demo-input-facebook-theme").tokenInput(beer, {
                theme: "facebook",
                propertyToSearch: "name",
                preventDuplicates: true,
                resultsLimit:'5',
                resultsFormatter: function(item){ return "<li>" + "<img src='http://graph.facebook.com/" + item.id + "/picture' title='" + item.id + "'  />" + "<div style='display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.name + " </div></div></li>" },
              tokenFormatter: function(item) {  return "<li><p>" + item.id + "</p></li>" },
            });               
});   

        });
        </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM