英文:
TypeError: undefined is not a function (near '...markedDates.push...')
问题
当我使用React Native开发应用时,出现了以下问题。
> TypeError: undefined is not a function (near '...markedDates.push...')
我试图将以下数据放入markedDates中。
{'2023-03-03': {marked: true, dotColor: 'blue'}}
然而,我搜索了很多信息,但找不到与我的情况相符的情况。
这是我的代码。
import React from 'react';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import {Calendar} from "react-native-calendars";
import {View, StyleSheet} from 'react-native';
function HomeScreen({navigation}) {
var dateString = "";
var markedDates = {
'2023-02-01': {marked: true, dotColor: 'red'},
}
markedDates.push({'2023-03-03': {marked: true, dotColor: 'blue'}});
return(
<SafeAreaProvider>
<View>
<Calendar
markedDates={markedDates}
onDayPress={(day) => {
}}
/>
</View>
</SafeAreaProvider>
);
}
export default HomeScreen;
这个问题是否有人可以解决?如果可以的话,请帮助我。谢谢。
英文:
When I was developing an app using React Native, the following problem occurred.
> TypeError: undefined is not a function (near '...markedDates.push...')
I'm trying to put the following data into markedDates.
{'2023-03-03': {marked: true, dotColor: 'blue'}}
However, I searched a lot of information, but I couldn't find a situation that corresponds to my situation.
This is my code.
import React from 'react';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import {Calendar} from "react-native-calendars";
import {View, StyleSheet} from 'react-native';
function HomeScreen({navigation}) {
var dateString = "";
var markedDates = {
'2023-02-01': {marked: true, dotColor: 'red'},
}
markedDates.push({'2023-03-03': {marked: true, dotColor: 'blue'}});
return(
<SafeAreaProvider>
<View>
<Calendar
markedDates={markedDates}
onDayPress={(day) => {
}}
/>
</View>
</SafeAreaProvider>
);
}
export default HomeScreen;
Is there anyone who can solve this problem? If so, please help me. Thank you.
答案1
得分: 1
markedDates
被初始化为一个对象,而不是一个数组。因此,你不能在它上面使用 push()
方法。
英文:
markedDates
is initialized as an object, not an array. Therefore, you cannot use the push()
method on it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论