第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何刪除 ReactNative(JS) 列表中的特定元素

如何刪除 ReactNative(JS) 列表中的特定元素

嗶嗶one 2023-03-18 16:43:43
我制作了一個(gè)待辦事項(xiàng)列表,無(wú)論我輸入什么都會(huì)被推送到一個(gè)數(shù)組中。當(dāng)我映射數(shù)組時(shí),我放了一個(gè)垃圾桶按鈕,他們可以在其中刪除“待辦事項(xiàng)”列表。我嘗試了Splice方法,但沒(méi)有用。例如,我有一個(gè)列表,上面寫著:“買牛奶”“拿雞蛋”如果我想刪除“Get Eggs”,它會(huì)刪除“Buy Milk”(它會(huì)刪除頂部的任何內(nèi)容)。有人可以幫助我如何實(shí)現(xiàn)這一目標(biāo)。這是我的代碼(React 本機(jī)代碼):removeList = (item) => {  let val = this.state.noteList;  let arr = val.splice(item, 1); // <= this is what I did but it is removing the first element of the list  let complete = this.state.completedTask;  complete.push(arr); this.setState({ arr})};這是我的可觸摸不透明度:<TouchableOpacity  onPress={this.removeList}  style={{    height: deviceHeight / 10,    width: deviceWidth / 6,    backgroundColor: "#e6a25c",    justifyContent: "center",  }}>  <AntDesign    name="checkcircleo"    size={45}    color="black"    style={{ alignSelf: "center" }}  /></TouchableOpacity>;這對(duì)你來(lái)說(shuō)似乎是一個(gè)愚蠢的問(wèn)題,但我似乎無(wú)法弄清楚。編輯:我試圖做一個(gè)平面列表而不是映射,但它對(duì)我不起作用。難道我做錯(cuò)了什么:let newNote = [] // This is new NOTE and NOT THE COMPLETED SCREENnewNote.push(  <FlatList     data={this.state.noteList}         ListHeaderComponent={this.renderHeader}        renderItem={({item,index}) => {        <View style={{height:100,width:200,backgroundColor: "black"}}>           <View style={styles.newBoxView}>        <Text>{item}</Text>      </View>      </View>         }}  />  )
查看完整描述

2 回答

?
慕勒3428872

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超6個(gè)贊

我找到了我的答案,所以如果有人遇到同樣的問(wèn)題,這里是代碼:


`deleteNote = (index) => {

console.log(index)

 let arr = this.state.noteList;

 delete arr[index]

 this.setState({

  activeCounter: Number(this.state.activeCounter - 1)

 })

}`

這是我的映射代碼:


  `this.state.noteList.map((item,index) => 

   <View style={styles.createBox}>  

   <View style={{flex:4,justifyContent: 'center',backgroundColor: 

   "lightpink",}}>

    <Text  style={{textAlign:'center',fontSize:deviceWidth/20,}}>

    {item.trim()}

  

  </Text>

</View>

<TouchableOpacity key={index} onPress={() => this.deleteNote(index)} style={{flex:1,justifyContent: 'center'}}>

<AntDesign  name="checkcircleo" style={{alignSelf:'center',backgroundColor: "#e6a25c"}} size={deviceWidth/5} color="black" />

</TouchableOpacity>

)`

我希望這有幫助。這實(shí)際上花了我 1 周的時(shí)間才弄清楚,最后我弄明白了。


查看完整回答
反對(duì) 回復(fù) 2023-03-18
?
不負(fù)相思意

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊

嘗試這個(gè):


removeList = (item) => {

  let val = this.state.noteList;

  let arr;


  for (let i = 0; i < val.length; i++) {

    if (val[i] === item) {

      arr = val.splice(i, 1);

    }

  }


  let complete = this.state.completedTask;

  complete.push(arr);

};


查看完整回答
反對(duì) 回復(fù) 2023-03-18
  • 2 回答
  • 0 關(guān)注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)