1
私はJsonを使用してHTMLページにSPARQLクエリの結果を表示しましたが、特定の値が入力され、警告ボックス。 bindings
が空の場合、今では何も表示されない、それだけでtrHeaders
を示し用としてjson値が与えられていないときに警告ボックスを表示する方法
HTML
<table id="results">
</table>
クエリスクリプト
var query = [
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>",
"PREFIX yago: <http://dbpedia.org/class/yago/>",
"PREFIX type: <http://dbpedia.org/class/yago/>",
"PREFIX prop: <http://dbpedia.org/property/>",
"SELECT ?name ?runtime",
"WHERE {",
"?film rdf:type dbo:Film.",
"?film dbp:name ?name.",
"?film dbo:director dbr:Peter_Jackson.",
"} GROUP BY ?name ?runtime"
].join(" ");
alert("this query: [" + query + "]");
var queryUrl = url + "?query=" + encodeURIComponent(query) + "&format=json";
console.log(queryUrl);
$.ajax({
dataType: "jsonp",
url: queryUrl,
success: function (data) {
console.log(data);
// get the table element
var table = $("#results");
// get the sparql variables from the 'head' of the data.
var headerVars = data.head.vars;
// using the vars, make some table headers and add them to the table;
var trHeaders = getTableHeaders(headerVars);
table.append(trHeaders);
// grab the actual results from the data.
var bindings = data.results.bindings;
// for each result, make a table row and add it to the table.
for (rowIdx in bindings) {
table.append(getTableRow(headerVars, bindings[rowIdx]));
}
if (bindings.trim().length == 0) {
alert("empty"); //IF BINDING IS EMPTY DISPLAY ALERT BOX
}
}
});
:私のコードは以下の通りです。
bindings
が空の場合、または<td>
が空の場合、どのように警告ボックスをポップアップ表示できますか? この質問が理解されたことを願っています。御時間ありがとうございます。
はこれを試してください(result.bindings){} 他のアラート( '空')ここで、あなたは)(bindings.trimのためにチェックしている長さ== 0をクエリのSCRIに。 pt –
人々がここで宿題をしているようです:最後の日に同じコードで質問しましたhttp://stackoverflow.com/questions/41617269/json-data-from-sparql-query-not-displaying-on-table and http://stackoverflow.com/questions/41602590/display-alert-box-when-table-element-has-no-text。重複としてマークする必要があります – AKSW