微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在ReactJS

如何解决在ReactJS

我对ReactJS还是很陌生,我试图在输入字段中输入内容,但是它只覆盖1个数字,然后光标消失了,我希望光标保持在原来的位置,这样我就可以输入任意数量的数字。 我看了好几本教程,但是在我的情况下却没有其中的一本。 感谢您对此事的协助

this.handleInputChange = this.handleInputChange.bind(this)

this.state = {
  coordinatesList: [
     [29.294957293,30.1027401502],[30.193056150,26.1047492638]
]
}

//coordinatesList returns a an array list of arrays with 2 index
// I want to display each index seperatly,that's why I used item[0]

<SortableContainer coordinatesList={this.state.coordinatesList} drag= 
 {this.handleDragging}>
      {this.state.coordinatesList.map((item,index) => (
        <SortableItem
          key={item}
          index={index}
          className="sortable-item"
        >
          <SortIcon />
          <input onChange={(e) => this.handleInputChange(e,index)} type="text" value={item[0]} />
        </SortableItem>
      ))}
    </SortableContainer>


handleInputChange(e,index){
 let updatedState = [...this.state.coordinatesList];
 updatedState[index] = [Number(e.target.value),this.state.coordinatesList[index][1]]
 
 this.vectorLayer.clear();
 apiRegistry
  .getApis(["Feature"])
  .then(([Feature]) => {
    var feature = new Feature({
      "type": "Feature","geometry": {
        "type": "polygon","coordinates": [this.state.coordinatesList]
      },"properties": {
      }
    })
    this.vectorLayer.addFeature(feature);
    this.setState({
      coordinatesList: updatedState
    })
  });

}

解决方法

这是您的解决方案

import tensorflow as tf
from tensorflow.keras.layers import Input,Reshape,TimeDistributed

whole_images = Input(shape=(img_rows,img_cols,1))
patches = tf.image.extract_patches(
    whole_images,sizes=[1,25,1],strides=[1,1,# you can choose to increase the stride if you don't want a dense classification map
    rates=[1,padding='SAME'
)
# The `patches` would have a shape of `(batch_size,num_row_locs,num_col_locs,25*25)`.
# So we reshape it so that we can apply the classifier to each patch independently.
reshaped_patches = Reshape((-1,1))(patches)
dense_map = TimeDistributed(letter_classifier)(reshaped_patches)
# Reshape it back
dense_map = Reshape(tf.shape(patches)[1:-1])(dense_map)

# Construct the model
image_classifier = Model(whole_images,dense_map)

# Use it on the real images
output = image_classifier(my_images)
,

我认为现在有一种简单的方法可以做到这一点。您可以使用此代码来更新输入。

class Input extends Component {
  state = {
    yourInput: '',};

  handleInput = (e) => {
    this.setState({yourInput: e.target.value});
  };

  render() {
    return (
      <div>
        <h2>{this.state.yourInput}</h2>
        <input onChange={this.handleInput} value={this.state.yourInput} />
      </div>
    );
  }
}

为简便起见,请尝试基于此修改代码。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。