0

このプラグインでは、すべてが正常に機能します。ここでは、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"}
        ]

しかし、私の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"
   }
}

これは、jsonを解析しているjavascriptです。

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

前もって感謝します。

4

1 に答える 1

0

私は解決策を得ました

    <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>
于 2012-11-07T09:01:46.173 に答える