我正在尝试显示从维基百科API的响应中获取的结果列表.如果响应未显示任何列表,则应显示不同的消息.我正在尝试进行条件渲染.
这是代码:
getData(e) {
e.preventDefault();
var search = e.target.search.value;
var wikipediaEndPoint = "https://en.wikipedia.org/w/api.php?format=json&origin=*&action=query&generator=search&gsrnamespace=0&prop=pageimages|extracts&pilimit=max&exintro&explaintext&exsentences=1&exlimit=max&gsrsearch="+search;
var wikipediaUrl = "https://en.wikipedia.org/?curid=";
fetch(wikipediaEndPoint)
.then(data => {
return data.json();
}).then(data => {
var objectList = (data.hasOwnProperty("query")) ? data.query.pages : "";
let resultList;
if(objectList !== ""){
resultList = Object.keys(objectList).map(function(key, index) {
return (
<div className="item" key={objectList[key].pageid}>
<a href={wikipediaUrl+objectList[key].pageid}>
<h1>{objectList[key].title}</h1>
<p>{objectList[key].extract}</p>
</a>
</div>
)
});
} else {
resultList = (function() {
return (
<div className="item" key={1}>
<p>No results!</p>
</div>
)
});
}
this.setState({search: resultList});
})
}
Run Code Online (Sandbox Code Playgroud)
结果如下所示: …
我正在尝试使用mongoimport以下命令行导入 json 文件:
mongoimport --db posts --collection rows --file post_history.json
Run Code Online (Sandbox Code Playgroud)
但它返回此错误:
connected to: localhost
Failed: error processing document #1: invalid character 'N' after object key:value pair
imported 0 documents
Run Code Online (Sandbox Code Playgroud)
该文件的内容如下所示:
[
{
"Id" : 1,
"PostHistoryTypeId" : 2,
"PostId" : 1,
"RevisionGUID" : "1e04af17-3bdb-4263-aa46-97ee7fb1b0b6",
"CreationDate" : "2011-06-21 20:19:34",
"UserId" : 9,
"Text" : "My finance and myself are looking for a good Caribbean cruise in October and were wondering which islands are best to see and which Cruise …Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下命令启动Spark应用程序:
time spark-submit --master "local[4]" optimize-spark.py
Run Code Online (Sandbox Code Playgroud)
但是我得到了这些错误:
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
16/01/27 15:43:32 INFO SparkContext: Running Spark version 1.6.0
16/01/27 15:43:32 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
16/01/27 15:43:32 INFO SecurityManager: Changing view acls to: DamianFox
16/01/27 15:43:32 INFO SecurityManager: Changing modify acls to: DamianFox
16/01/27 15:43:32 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users with view permissions: Set(DamianFox); users with modify permissions: Set(DamianFox)
16/01/27 15:43:33 INFO Utils: …Run Code Online (Sandbox Code Playgroud)