为什么 STRAFTER return 将 json 中的空白数据绑定到 angular 中?
Why does STRAFTER return blank data in json binding in angular?
我正在使用 angular 绑定 SPARQL 查询的结果。
它工作得很好,直到我尝试使用 SPARQL "STRAFTER" 或 "REPLACE" 函数(下面的代码)绑定从查询返回的数据,其中 returns $scope 中的空白数据。但是,如果我直接从 Fuseki 控制面板 运行 将输出设置为 json,则相同的查询工作正常。
我正在使用 Fuseki Server 1-1.1.2 端点 (SPARQL 1.1)。
这是 returns 预期 Fuseki 服务器中的数据的查询:
SELECT (strafter(str(?class),"#") AS ?className) (COUNT(?s) AS ?count )
{ ?s a ?class }
GROUP BY ?class ORDER BY DESC(?count)
这是在“$http.get”调用中使用相同查询的 HTML/angular 代码,响应绑定在 angular 返回为空白:
<div ng-app="myApp" ng-controller="queryCtrl"><table>
<tr ng-repeat="x in results">
<td>{{x.class.value}}</td>
<td>{{x.count.value}}</td>
</tr>
</table></div>
<script>
var app = angular.module('myApp', []);
app.controller('queryCtrl', function($scope, $http) {
var query = encodeURIComponent("SELECT (strafter(str(?class), "#") AS ? className) (COUNT(?s) AS ?count) {?s a ?class} GROUP BY ?class ORDER BY DESC(? count)");
var endpoint = "http://localhost:3030/dataset/query";
$scope.results = [];
$http.get("http://localhost:3030/dataset/query? query="+query+"&output=json")
.success(function (response) {
$scope.results = response.results.bindings;
/* for debugging*/
if ( window.console && window.console.log ) {
// console is available, write message if something has happened
console.log(response.results);
}
});
});
</script>
请问为什么会这样?
这可能是字符串引用问题,因为您 "
字符串被 #
前面的 "
终止。所以尝试:
var query = encodeURIComponent('SELECT (strafter(str(?class),"#") AS ?className) (COUNT(?s) AS ?count ) WHERE { ?s a ?class } GROUP BY ?class ORDER BY DESC(?count)');
我正在使用 angular 绑定 SPARQL 查询的结果。
它工作得很好,直到我尝试使用 SPARQL "STRAFTER" 或 "REPLACE" 函数(下面的代码)绑定从查询返回的数据,其中 returns $scope 中的空白数据。但是,如果我直接从 Fuseki 控制面板 运行 将输出设置为 json,则相同的查询工作正常。
我正在使用 Fuseki Server 1-1.1.2 端点 (SPARQL 1.1)。
这是 returns 预期 Fuseki 服务器中的数据的查询:
SELECT (strafter(str(?class),"#") AS ?className) (COUNT(?s) AS ?count )
{ ?s a ?class }
GROUP BY ?class ORDER BY DESC(?count)
这是在“$http.get”调用中使用相同查询的 HTML/angular 代码,响应绑定在 angular 返回为空白:
<div ng-app="myApp" ng-controller="queryCtrl"><table>
<tr ng-repeat="x in results">
<td>{{x.class.value}}</td>
<td>{{x.count.value}}</td>
</tr>
</table></div>
<script>
var app = angular.module('myApp', []);
app.controller('queryCtrl', function($scope, $http) {
var query = encodeURIComponent("SELECT (strafter(str(?class), "#") AS ? className) (COUNT(?s) AS ?count) {?s a ?class} GROUP BY ?class ORDER BY DESC(? count)");
var endpoint = "http://localhost:3030/dataset/query";
$scope.results = [];
$http.get("http://localhost:3030/dataset/query? query="+query+"&output=json")
.success(function (response) {
$scope.results = response.results.bindings;
/* for debugging*/
if ( window.console && window.console.log ) {
// console is available, write message if something has happened
console.log(response.results);
}
});
});
</script>
请问为什么会这样?
这可能是字符串引用问题,因为您 "
字符串被 #
前面的 "
终止。所以尝试:
var query = encodeURIComponent('SELECT (strafter(str(?class),"#") AS ?className) (COUNT(?s) AS ?count ) WHERE { ?s a ?class } GROUP BY ?class ORDER BY DESC(?count)');