Ionic 3 - 提供的参数与调用目标的任何签名都不匹配

Ionic 3 - Supplied parameters do not match any signature of call target

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

它给我一个错误 "Supplied parameters do not match any signature of call target"

  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: bob, fav: banana}, {name: ed, fav: grape}, {name: john}的数组中删除{name: john, fav: apple} , 最爱: 苹果}

提前致谢

您收到的错误是因为您使用错误的 properties/types 触发命令。我的猜测是它是删除命令。我不知道您是否有一个名为 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);

希望对您有所帮助..