小编9mi*_*day的帖子

如何修复 JSX 表达式必须有一个父元素?

我正在尝试在本机反应中切换模态。平面列表中的每个项目都应该有一个切换选项来打开一个模式。

我收到错误消息:JSX 表达式必须有一个父元素。

我试图用谷歌搜索正确的语法,但找不到解决方案。

class CategoriesScreen extends Component {

  state = {
    modalVisible: false,
  };

  setModalVisible(visible) {
    this.setState({ modalVisible: visible });
  }

  render() {
function Item({ title }) {
      return (
        <TouchableOpacity style={styles.item} onPress={() => {
          this.setModalVisible(true);
        }}>
          <View>
            <Text style={styles.title}>{title}</Text>
          </View>
        </TouchableOpacity> 
        <Modal
          animationType="slide"
          transparent={false}
          visible={this.state.modalVisible}
          onRequestClose={() => {
            Alert.alert('Modal has been closed.');
          }}>
          <View style={{ marginTop: 22 }}>
            <View>
              <Text>Hello World!</Text>

              <TouchableOpacity
                onPress={() => {
                  this.setModalVisible(!this.state.modalVisible);
                }}>
                <Text>Hide Modal</Text>
              </TouchableOpacity>
            </View>
          </View>
        </Modal>
    };
    return (
      <SafeAreaView style={styles.container}> …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native

9
推荐指数
1
解决办法
2万
查看次数

如何修复 React '未定义 no-undef'?

我正在尝试为电影列表中的每部电影创建详细视图。我有 Django 作为后端,React 作为前端。

当我尝试对每部电影进行详细查看时,出现错误。

错误日志:

Failed to compile.

./src/components/movie-list.js
  Line 5:26:  'movie' is not defined  no-undef
  Line 6:28:  'movie' is not defined  no-undef

Search for the keywords to learn more about each error.
Run Code Online (Sandbox Code Playgroud)

我尝试过绑定,但不完全明白问题出在哪里。

应用程序.js

import React, { Component } from 'react';
import MovieList from "./components/movie-list";

  componentDidMount() {
    //fetch data
    fetch('http://127.0.0.1:8000/api/movies/', {
      method: 'GET',
      headers: {
        'Authorization': 'Token 8588cb6fcc2ee0bf9915d4c6b720554347d5883f'
      }
    }).then(resp => resp.json())
      .then(res => this.setState({ movies: res }))
      .catch(error => console.log(error))
  }

  movieClicked = movie => {
    console.log(movie); …
Run Code Online (Sandbox Code Playgroud)

reactjs

6
推荐指数
1
解决办法
7万
查看次数

如果元素有类

我试图通过测试元素是否具有sv或en类(瑞典语或英语)来翻译字段错误

我尝试访问该类,但不会影响javascript结果。


input.oninvalid = function(event) {
  if ($("wgcurrent").hasClass("en")) { 
    event.target.setCustomValidity("Letters only please");  
  } else if ($("wgcurrent").hasClass("sv")) {
    event.target.setCustomValidity("Vänligen ange endast bokstäver");
  }  

}
Run Code Online (Sandbox Code Playgroud)
<div class="wgcurrent wg-li wg-flags  flag-1 en" data-l="en" tabindex="0" aria-expanded="false" role="combobox" aria-label="Language selection: English"><a tabindex="-1" href="javascript:%20void(0);">English</a></div>
Run Code Online (Sandbox Code Playgroud)

我想确保输入函数为错误消息设置正确的值。我需要更改什么?

javascript jquery

0
推荐指数
1
解决办法
62
查看次数

标签 统计

reactjs ×2

javascript ×1

jquery ×1

react-native ×1