【问题标题】:Ionic 3 - Supplied parameters do not match any signature of call targetIonic 3 - 提供的参数与调用目标的任何签名都不匹配
【发布时间】:2017-05-01 17:53:19
【问题描述】:

我正在尝试从数组中删除单个对象,我该怎么做? 我尝试按照 ionic 指示使用 this.storage.remove('details') here 但它会删除所有数组,这是我目前的尝试:

它给了我一个错误“提供的参数与调用目标的任何签名都不匹配”

  private details: {name: string, fav: string}[] = []; 

  hapusDetail(val) {
  let test: string[] = [val]

  this.storage.remove(toString(test)) //really lost here
  //console.log(val)
  }


> Cordova CLI: 6.5.0 
> Ionic Framework Version: 3.1.1
> Ionic CLI Version: 2.2.3
> Ionic App Lib Version: 2.2.1
> Ionic App Scripts Version: 1.3.6
> ios-deploy version: Not installed
> ios-sim version: Not installed
> OS: Linux 4.8
> Node Version: v6.10.2
> Xcode version: Not installed

val 包含要删除的所需对象,例如{name: john, fav: apple}

基本上我需要的是从包含 {name: bob, fav:banana}, {name: ed, fav: grape}, {name: john, fav : 苹果}

提前谢谢你

【问题讨论】:

    标签: angular ionic-framework ionic2 ionic3


    【解决方案1】:

    您遇到的错误是因为您正在使用错误的属性/类型触发命令。我的猜测是它的删除命令。我不知道你是否有一个名为toString() 的函数,但我猜这就是问题所在。尝试将其设为'UserData' 之类的基本字符串,然后查看错误是否仍然显示。

    但这并不能解决您的实际问题,

    存储与用户设备上保存的数据集特别相关。如果要从数组中删除特定项目(暂时),您需要首先确定它的位置,然后将其从数组中删除。

    例子:

    let myArray = ['apples', 'oranges', 'bananas'];
    
    // find oranges
    let position = myArray.indexOf('oranges');
    
    //splice it out
    myArray.splice(position, 1);
    

    如果您也想从本地存储的数据中删除它,您只需要首先对整个阵列执行操作,然后存储它而不是删除它。当您使用 Ionic 存储对象时,您给它们命名,您的代码实际上看起来像是您打算将值转换为字符串。

    让我分解一下:

    // Get the saved stuff, Ionic will convert it for you
    let userData = this.storage.get('UserData');
    
    // Lets say favorite fruit is a value of the user data.
    
    let fruit = userData.fruit; // ['apples', 'oranges', 'bananas']
    
    // find oranges
    let position = myArray.indexOf('oranges');
    
    //splice it out, remember fruit is a shorthand reference to userData.fruit
    fruit.splice(position, 1);
    
    // Now, the data we save/load is called 'UserData' it has nothing to do with the data itself
    
    this.storage.set('UserData', userData);
    

    希望对您有所帮助..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-09
      • 2017-04-28
      • 2017-08-24
      • 2017-02-25
      • 2017-07-26
      • 2018-03-31
      • 2017-05-08
      相关资源
      最近更新 更多