【发布时间】:2017-07-08 10:06:40
【问题描述】:
我正在尝试在 this SO question 上使用 angular 来完成这个人所说的操作
他的代码是:
.controller('WikiQueryCtrl', ['$scope', '$http', function($scope, $http) {
$http({
//these geo coordinates and the date ranges will eventually be dynamic.
url: 'https://wdq.wmflabs.org/api?q=AROUND[625,-25.911389,31.957222,5]%20AND%20BETWEEN[585,1985,1987]&callback=JSON_CALLBACK',
method: 'jsonp'
})
.success(function(response) {
var items = response.items;
$scope.jason = items;
var wikiDataString = 'http://www.wikidata.org/w/api.php?action=wbgetentities&format=json&ids=Q' + items + '&props=sitelinks%7Csitelinks%2Furls&callback=JSON_CALLBACK';
$http({
url: wikiDataString,
method: 'jsonp'
})
.success(function(response2) {
$scope.jason2 = response2;
var url = response2.entities["Q" + items].sitelinks.enwiki.url;
var wikipediaTitle = url.substr(24, url.length);
var wikipediaURL = 'http://en.wikipedia.org/w/api.php?action=query&prop=extracts|info&exintro&titles=' + wikipediaTitle + '&format=json&explaintext&redirects&inprop=url&indexpageids&format=json&callback=JSON_CALLBACK';
$http({
url: wikipediaURL,
method: 'jsonp'
}).success(function(response4) {
var query = response4.query;
var pageID = response4.query.pageids;
var title = response4.query.pages[pageID].title;
var fullurl = response4.query.pages[pageID].fullurl;
var content = response4.query.pages[pageID].extract;
$scope.title = title;
$scope.content = content;
$scope.fullurl = fullurl;
$scope.jason = query;
});
});
});
}]);
我知道 wikipedia 有一个 geosearch 但没有日期范围,我试着像那个家伙所做的那样查看 wikidata 并将其转换为 jQuery 但没有积极的结果,这是一个代码笔:
https://codepen.io/anon/pen/PjywjR
我将如何在 jQuery 中实现他所说的使用 Angular 实现的功能,通过坐标和日期范围搜索维基百科内容。
【问题讨论】:
-
一个建议:删除引用的代码(指向该代码的链接)并粘贴到您的代码中(在 codepen.io 链接上)。
标签: jquery wikipedia-api mediawiki-api wikidata