在React Native中更新MapView注释

时间:2016-05-15 06:35:51

标签: javascript react-native jsx

我好几天都在讨论这个问题。我在项目中创建了一个MapView,我加载了Annotations和别针。

在注释中,我有两个按钮(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),
    ...
});

_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>
          ...
  );
}

最后,upvote(key)函数。

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

enter image description here

0 个答案:

没有答案