[英]React-Native How to get an array from a function in the constructor of another class
我想在另一個類中使用來自外部函數的數組。 因此,此函數返回一個數組:
function getMarkers() {
var markers = [];
markers.push("example: exmple");
return(markers);
}
我想在下面的類的構造函數中使用該數組:
class Home extends Component {
constructor() {
super();
this.state = { getMarkers }
不幸的是,這不起作用。 有什么建議么?
在您的示例中, getMarkers
是一個返回數組的函數。 如果要獲取該數組,則必須調用此函數:
const markers = getMarkers();
console.log(markers); // prints: ["example: exmple"]
this.state = { markers }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.