【问题标题】:Store different arrays in Ionic Storage在 Ionic Storage 中存储不同的数组
【发布时间】:2020-05-04 01:25:46
【问题描述】:

我正在尝试使用带有一堆不同字段的提交页面来提交有关单个蜂箱的详细信息(名称、位置、cmets 等)。我打算使用离子存储,如果这是最好的方法,则将数据放入数组中,然后使用列表显示所有项目,然后您可以单击以转到有关蜂巢的特定详细信息.

到目前为止,我正在尝试做这样的事情,但不确定这是否在正确的轨道上:

  submitHive() {
this.navCtrl.push(ViewHivePage)
let data={'name': this.name, 'location': this.location, 'address': this.address, 'date': this.date, 'weight': this.weight, 'comments': this.comments}
console.log(data)
this.hiveData={
  name:this.name,
  location:this.location,
  address:this.address,
  date:this.date,
  weight:this.weight,
  comments:this.comments
}

从输入字段推送数据,然后转到新页面以显示详细信息。我正在使用[(ngModel)] 推送数据,这是在正确的轨道上吗? 谢谢!

【问题讨论】:

  • 你的问题不清楚。请描述更多

标签: ionic-framework ionic3


【解决方案1】:

如果您可以使用角度形式而不是使用多个 [(ngModel)],那就更好了。因为 Angular Form 的实现比这更清楚。尝试像下面这样使用

_dataForm: FormGroup;
_hiveData;

ngOnInit() {
    this.initForm();
}

initForm() {
    this._dataForm = new FormGroup({
     name: new FormControl("", Validator.required),
     ...
    });
}

saveData() {
    // check the validation if needs
    this.hiveData = this._dataForm.value;
    // save the data
    this.navCtrl.push(ViewHivePage, {hiveData: this.hiveData});
    // you can take this data from other component using navparams
}

模板

<form [formGroup]="_dataForm">
 <input type="text" formControlName="name">
 ...
</form>

【讨论】:

    猜你喜欢
    • 2020-02-06
    • 2018-02-22
    • 2017-11-12
    • 2016-11-23
    • 1970-01-01
    • 2018-01-05
    • 2021-04-07
    • 1970-01-01
    • 2016-09-03
    相关资源
    最近更新 更多