How to set default Checked in checkbox ReactJS?

前端 未结 16 1932
难免孤独
难免孤独 2020-11-27 11:51

I\'m having trouble to update the checkbox state after it\'s assigned with default value checked="checked" in React.

var rCheck = React         


        
16条回答
  •  孤城傲影
    2020-11-27 12:23

    this can be done with pure js

                  
                    
                  
    
    
      //Load category to form : to edit
      GetCategoryById(id) {
        this.UpdateId = id
        axios.get('http://localhost:4000/Category/edit/' + id)
          .then(response => {
            this.setState({
              category_name: response.data.category_name,
              category_description: response.data.category_description,
              is_active: response.data.is_active,
            });
    
            response.data.is_active == 1 ? document.getElementById("categoryStatus").checked = true : document.getElementById("categoryStatus").checked = false;
          })
          .catch(function (error) {
            console.log(error);
          })
      }
    
    
    

提交回复
热议问题