简体   繁体   English

Ionic5 拆分字符串

[英]Ionic5 split string

Hello i want to split a string i get from a db row.您好,我想拆分从数据库行中获取的字符串。 The string is tags i use.该字符串是我使用的标签。 I import them in db row as a text我将它们作为文本导入数据库行

eg the string is (#Hello, #hi, #hellothere )例如字符串是 (#Hello, #hi, #hellothere )

and i want to split the tags like this to use each word as a button我想像这样拆分标签以将每个单词用作按钮

<ion-row class="item-tags" *ngIf="item.tags?.length>0">
   <ion-col class="tag-wrapper">
      <span class="item-tag">
         <ion-note>{{item.tags}}</ion-note>
      </span>
   </ion-col>
 </ion-row>

.ts function .ts function

 export class UserPage implements OnInit {
     usersFlows:any =[];
       tagsArray: any;

    constructor(){}




usersFlowsSet() {//
this.offset = 0; 
this.userData.usersFlow().pipe(
  map((data:any) => {
    if (data.success) {
      this.usersFlows = data.userFlows;
      this.tagsArray = this.usersFlows.tags.replace(/#/g,'').split(', ')
    }
   })
 ).subscribe()
}

Any help?有什么帮助吗?

and i want to split the tags like this to use each word as a button我想像这样拆分标签以将每个单词用作按钮

Since you want to do this, why don't you split the tags inside your controller file.既然你想这样做,为什么不在你的 controller 文件中拆分标签。

.split function will not work in your html template. .split function 在您的 html 模板中不起作用。

this.tagsArray = this.item.tags.replace(/#/g,'').split(', ')

Then inside your template然后在你的模板中

<span class="item-tag" *ngFor="let tag of tagsArray">
   <ion-button>{{tag}}</ion-button>
</span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM