我是React的新手并且陷入了这个愚蠢的事情,
我有一个名为的组件,我传递的几个道具
<android.support.v7.widget.CardView
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginLeft="14dp"
android:layout_marginBottom="14dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="10dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/gallary_iv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/white_bg_iv"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/pic_photo_number_bg"
app:layout_constraintBottom_toBottomOf="@+id/gallary_iv"
app:layout_constraintEnd_toEndOf="@+id/gallary_iv"
app:layout_constraintStart_toStartOf="@+id/gallary_iv"
app:layout_constraintTop_toTopOf="@+id/gallary_iv" />
<TextView
android:id="@+id/pic_count_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:textSize="16sp"
android:textColor="#506876"
app:layout_constraintTop_toTopOf="@+id/white_bg_iv"
app:layout_constraintBottom_toBottomOf="@+id/white_bg_iv"
app:layout_constraintStart_toStartOf="@+id/white_bg_iv"
app:layout_constraintEnd_toEndOf="@id/white_bg_iv"/>
</android.support.constraint.ConstraintLayout>
我需要格式化<VideoDetail
video={this.state.selectedVideo}
viewCount={this.state.selectedViewCount}
/>
viewCount
我知道如何在JS中格式化字符串作为我的要求但是我如何在viewCount中使用它或者还有其他方法吗?
P.S。如果viewCount为10944431,我需要将其格式化为10,944,431
更新: 对不起,但我已经告诉过我知道如何在JS格式化,所以我认为它不是重复的,而是viewCount的类型String?
答案 0 :(得分:1)
How to print a number with commas as thousands separators in JavaScript
在此处申请:
const VideoDetail = ({video,viewCount}) => {
return (
<p className="views">
<i className="material-icons">
remove_red_eye
</i>
{viewCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}
</p>
);
};