【发布时间】:2019-10-25 14:23:33
【问题描述】:
const [ data, setData ] = useState( [] );
useEffect( () => {
axios( {
method: "GET",
url: "https://bouvet.guru/rekrytering_flera.php"
} ).then( ( response ) => {
if ( response.data.indexOf( "https://" ) !== -1 ) {
let splittedArray = response.data.split( "Data:" );
let dataString = splittedArray[1];
if ( dataString.includes( "<URL kommentar>" ) ) {
let onlyData = dataString.substring( 16 );
let pairedData = onlyData.split( "https://" );
pairedData.splice( 0, 1 );
pairedData.map( ( group ) => {
let urls = group.split( " " )[0];
const comments = group.replace( urls, " " );
setData( {
item: {
url: "https://" + urls,
comment: comments
}
} );
} );
} else {
console.log( "NOPE" );
}
} else {
console.log( "We could not find any data" );
}
} );
}, [] );
我有这个代码。
我想要什么:data = [obj1, obj2, obj3]。
我得到:数据 = obj1、obj2、obj3。
我希望对象位于数据数组中,但此刻,数据变成了一个对象。所以当我 console.log(data) 我得到 3 个单独的对象。我希望数据是一个数组,里面有这 3 个单独的对象。
【问题讨论】:
标签: javascript reactjs