条件形式

时间:2018-06-07 19:34:30

标签: angularjs regex

我的代码有点问题。 我想只显示存储在我的存储中的密钥,该密钥以'[“开头。 我不知道是否必须使用Angular - Pattern,因为我真的不明白它是如何工作的。

这是我的代码:

  constructor(public navCtrl: NavController,public _storage: Storage){
  this._storage.forEach( (value, key, index) => {
    //console.log("This is the value", value)
    //console.log("from the key", key)
    //console.log("Index is", index)
    this.questionnaires.push(key);
  })
}

此代码将保存推送到列表中,并显示所有保存。 我的存储中有两种保存:问卷(如:[日期]问卷n°X)和来自stopWatch的数据(如:XX min,xx sec,XX; ms)。

在存储中,显示所有保存,我想只有Quesitonnaire所以以[。

开头的形式

感谢您的时间!

主要问题的筛选:

The list into the app

The content of _storage

  

工作精细:if(key.length> = 1&& key [0] ==='['){code}

1 个答案:

答案 0 :(得分:1)

如果您当前的代码有效,请在推送之前检查密钥是否以[开头,如下所示:

constructor(public navCtrl: NavController,public _storage: Storage){
    this._storage.forEach( (value, key, index) => {
        if (key.length >= 1 && key[0] === '[')
            this.questionnaires.push(key);
    })
}
相关问题