简体   繁体   English

离子存储无法为字符串分配数字

[英]Ionic storage not assignable number to string

I want to set in ionic storage all numbers like from function below getWarrentsNumber(), but i've got an error. 我想在离子存储中设置所有数字,例如getWarrentsNumber()下面的函数中的所有数字,但是出现错误。

Error: Argument of type "number" is not assignable to type 'string. 错误:“数字”类型的参数无法分配给“字符串”类型。

this.storage.set(this.NumberOfAssignedWarrents, 'LOCAL STORAGE BROJ');
    this.storage.get('name').then((name) => {
      console.log('Me: Hey, ' + name + '! You have a very nice name.');
      console.log('You: Thanks! I got it for my birthday.');
    });
  },
  error => {

  }
  );

This is a function to catch number of tasks from db: 这是一个从数据库捕获大量任务的功能:

getWarrentsNumber() {

    let id = localStorage.getItem('userId');

    this.peopleProvider.getAllWorkerAssignedWarrents(id).toPromise()
      .then(result => {
        this.NumberOfAssignedWarrents = result.length;
        localStorage.setItem('DodNalog', result);
      });
    this.peopleProvider.getAllWorkerFinishedWarrents(id).toPromise()
      .then(result => {
        this.NumberOfFinishedWarrents = result.length;
        localStorage.setItem('ZavNalog', result);
      });
    this.peopleProvider.getAllWorkerUnfinishedWarrents(id).toPromise()
      .then(result => {
        this.NumberOfUnfinishedWarrents = result.length;
        localStorage.setItem('NezavNalog', result);
        console.log(result);
      });
  }

This line throws the error, because you are setting the key as a number. 此行引发错误,因为您将key设置为数字。 As per ionic docs, the first parameter ( key ) should be a string. 根据ionic docs,第一个参数( key )应为字符串。

this.storage.set(this.NumberOfAssignedWarrents, 'LOCAL STORAGE BROJ');

This should be changed as 这应该更改为

this.storage.set('LOCAL STORAGE BROJ',this.NumberOfAssignedWarrents);

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

相关问题 类型'字符'不能指定为'数字'类型 - Type 'string' is not assignable to type 'number' “数字”类型不能分配给“字符串”类型 - Type 'number' is not assignable to type 'string' 类型字符串不可分配给类型编号 - Type string is not assignable to type number 类型“字符串”不可分配给类型“RouterDirection” - Ionic 6 - angular - Type 'string' is not assignable to type 'RouterDirection' - Ionic 6 - angular “字符串”类型的参数不能分配给“数字”类型的参数 - Argument of type 'string' is not assignable to parameter of type 'number' 类型为'number'的参数不能赋值给'string'类型的参数 - argument of type 'number' is not assignable to a parameter of type 'string' 如何修复`类型号的参数不能分配给字符串`? - How to fix `Argument of type number is not assignable to string`? pipe 错误:类型“数字”不可分配给类型“字符串” - pipe error : Type 'number' is not assignable to type 'string' 错误:使用 toFixed() 无法将类型“字符串”分配给类型“数字” - Error: Type 'string' is not assignable to type 'number' with toFixed() “对象”类型的参数不可分配给“字符串”类型的参数 - 离子 Angular - Argument of type ‘Object’ is not assignable to parameter of type ‘string’ - Ionic Angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM