小编Jul*_*GER的帖子

如何更新使用 of(myArray) 创建的 RxJS Observable 的值

我在使用 Angular 和 Observable 时遇到了问题。

\n\n

我有一个 Basket 页面,订阅 BasketService 中数组的 Observable,其中包含我的客户订单。当我单击验证按钮时,我清空了订单数组,但即使我的购物篮页面已订阅了我的可观察对象,它也不会更新。

\n\n

在我的 BasketPage.ts 中

\n\n
  ngOnInit() {\nthis.nourritureSubscription = this.panierService.nourritureStore.subscribe((data) => {\n  if(data.length === 0) {\n    this.isNourriturePanierEmpty = true;\n  } else {\n    this.nourriturePanier = data;\n    console.log(data)\n    this.isNourriturePanierEmpty = false;\n  }\n});\nthis.menuSubscription = this.panierService.menuStore.subscribe((data) => {\n  if(data.length === 0) {\n    this.isMenuPanierEmpty = true;\n  } else {\n  this.menuPanier = data\n  console.log(data)\n  this.isMenuPanierEmpty = false;\n  }\n})\n}\nconsumePanier(){\nlet commandeSucess : boolean;\nthis.panierService.consumePanier()\nthis.commandeEnvoyee();\n}\nasync commandeEnvoyee() {\nconst alert = await this.alertCtrl.create({\n    header: 'Commande envoy\xc3\xa9e !',\n    message: 'Votre commande a …
Run Code Online (Sandbox Code Playgroud)

observable rxjs angular

3
推荐指数
1
解决办法
6109
查看次数

为什么我的 React-Native FlatList 中有相同键的 double ?

我正在尝试获取在以下端点描述的对象:https : //api.cosmicjs.com/v1/67302ce0-7681-11e9-8193-4bd8888ec129/objects? pretty =true&hide_metafields=true

您会注意到有一个带有唯一标识符的 _id 字段。

那么为什么我得到:

“警告:遇到两个具有相同密钥的孩子,:。密钥应该是唯一的,以便组件在更新时保持其身份。非唯一的密钥可能会导致孩子被复制和/或省略——这种行为不受支持,将来可能会改变版本。”

这是我的 FlatList 渲染:

render() {   
    if(this.props.dataToDisplay.objects){
        console.log(typeof(this.props.dataToDisplay.objects))
        console.log(this.props.dataToDisplay.objects)
        this.props.dataToDisplay.objects.forEach((item)=>{
            console.log(item)
        })

        return (
            <View style={[{backgroundColor: this.state.backgroundColor},styles.container]}>
                <FlatList
                    data={this.props.dataToDisplay.objects}
                    keyExtractor={(item, index)=>{item._id.toString()}}
                    renderItem={({item})=>{
                        <Text id={item._id}>{item.title}</Text>
                    }}
                />
            </View>
        );
}
 else {

    return (
        <View style={[{backgroundColor: 
this.state.backgroundColor},styles.container]}>
            <Text>Loading elements.</Text>
        </View>
      );
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

keyExtractor 会不会有问题?我尝试使用 keyExtractor={(item, index)=>{item._id}} 没有结果......

谢谢你的时间。

json react-native react-native-flatlist

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

将可拖动 div 的一部分设置为不可拖动

我正在使用 Angular Material CDK,特别是拖放功能,我想知道是否有任何方法可以将子 div 之一设置为不可拖动,同时仍然允许拖动父 div ?

    <div cdkDropList (cdkDropListDropped)="drop($event)">
        <div cdkDrag class="section" *ngFor="let section of sections">
            <sectionComponent dynamically appended trough a factory>
        </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

每个部分组件都可以拖动到父 cdkDropList 中。这是一个部分的结构。

    <div class="sectionContainer">
        <div class="sectionParam">
        </div>
        <div class="sectionContent">
        </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

我想要的是能够拖动整个部分,但前提是拖动的来源来自sectionContent div。我的 paramSection 中有一些滑块导致拖放功能出现问题。

谢谢你的时间。

drag-and-drop angular

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