在React Native中更新MapView注释

Chr*_*rdi 5 javascript jsx react-native

几天来,我一直在讨论这个问题.我MapView在我的项目中创建了一个用Annotations和pin加载的东西.

在注释中,我有两个按钮(upvote和downvote).按钮执行它们应该执行的操作,并与网络一起正常工作.但是,我不能让他们更新他们下面的柜台进行更新(如下图所示).

所以,问题是:如何动态更新upvote/downvote按钮下面的文本?

我的代码添加引脚w/Annotations:

//Add the new pin/annotation to the array
that.state.displayedDrops.splice(0,0, {
    ...
  title: dataSnapshot.val().author,
     //Next line calls a function that returns a <View> hierarchy.
  detailCalloutView: that._getAnnotationView(key, dataSnapshot.val().secret, dataSnapshot.val().author),
    ...
});
Run Code Online (Sandbox Code Playgroud)

_getAnnotationView(key, message, author)功能:

_getAnnotationView(key, message, author) {
  return(
          ...
    //This state stores the amount of upvotes for the given key
    <Text style={{alignSelf: 'center', fontSize: 30}}>{String(this.state["upvotes-".concat(key)])}</Text>
          ...
  );
}
Run Code Online (Sandbox Code Playgroud)

最后,upvote(key)功能.

upvote(key) {
  var that = this;
     ...
  if(committed) {
     that.setState({
        ["upvotes-".concat(key)]: dataSnapshot,
      });
   }
};
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述