简体   繁体   English

如何从和服中提取API

[英]How to pull an API from Kimono

We're looking for the best way to pull an API from Kimono Labs and how to structure properly. 我们正在寻找从Kimono Labs提取API的最佳方法,以及如何正确构建结构。 PLUNKER 朋克

Here is what we have in the app.js 这是app.js中的内容

var App = angular.module('App', []);

App.controller('Calendar', function($scope, $http) {
  $http.get('http://www.kimonolabs.com/api/42ts6px8?apikey=363e7e1d3fffb45d424ad535ebdc233d&callback=kimonoCallback')
       .then(function(res){
          $scope.events = res.data[0].events;                
        });
});

index... 指数...

<!doctype html>
<html ng-app="App" >
<head>
  <meta charset="utf-8">
  <title>Todos $http</title>
  <link rel="stylesheet" href="style.css">
  <script>document.write("<base href=\"" + document.location + "\" />");</script>
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.1/angular.js"></script>
  <script src="app.js"></script>

  <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  <script>
      function kimonoCallback(data) {
        // do something with the data
        // please make sure the scope of this function is global
      }

      $.ajax({
        "url":"http://www.kimonolabs.com/api/42ts6px8?apikey=363e7e1d3fffb45d424ad535ebdc233d&callback=kimonoCallback",
        "crossDomain":true,
        "dataType":"jsonp"
    });
  </script>
</head>
<body ng-controller="Calendar">
  <ul>
    <li ng-repeat="item in events">
      <h1>{{item.EventTitles.text}}</h1>
      <img src="{{item.HeadlineImages.src}}">
      <p>{{item.eventdescription}}</p>
    </li>
  </ul>
</body>
</html>

Are we doing this correctly? 我们这样做正确吗? We can get it to pull data from a local .json file... but not from Kimono? 我们可以从本地.json文件中提取数据,但不能从和服中提取数据吗?

Any help or a point in the right direction would be appreciated. 任何帮助或朝着正确方向的观点将不胜感激。 Thank you for your time. 感谢您的时间。

EDIT: I forgot to mention, I am aware of the API link from Kimono Labs I included does not work, this is intentional. 编辑:我忘了提及,我知道我包含的Kimono Labs的API链接不起作用,这是有意的。

EDIT2: Added a PLUNKER if that helps anyone. EDIT2:如果可以帮助任何人,则添加一个PLUNKER

Kimono actually has a tutorial for calling your API with Angular.js. Kimono实际上有一个使用Angular.js调用API的教程。 You can take a look at it through their docs at: https://help.kimonolabs.com/hc/en-us/articles/204380310-Tutorial-Calling-Kimono-with-AngularJS- 您可以通过以下网站的文档进行查看: https//help.kimonolabs.com/hc/en-us/articles/204380310-Tutorial-Calling-Kimono-with-AngularJS-

They also have pretty solid support if you email or chat them, in my experience. 根据我的经验,如果您通过电子邮件或聊天进行交流,他们也将提供非常可靠的支持。

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

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