【问题标题】:Ionic 4 Arrow FunctionsIonic 4 箭头函数
【发布时间】:2019-08-01 07:03:02
【问题描述】:

我正在使用 Ionic 4 创建一个待办事项列表应用程序。当用户单击添加任务时,会打开一个警报。但是,当将任务放入输入并单击添加任务按钮时,什么也没有发生。我觉得我的箭头功能有问题,但我对它们还不够熟悉,无法发现问题。我附上了一张我认为是问题的代码的照片以及我的 github 的链接。非常感谢您的反馈和解决方案!

To do list github

【问题讨论】:

    标签: ionic-framework alert arrow-functions ion-list


    【解决方案1】:

    我看到这里的代码有两个问题:

    1. this.tasks = this.taskList.valueChanges(); 这将返回一个 observable,因此您必须使用异步管道在模板中检索其值,例如:

      *ngFor="let task of tasks | async"

    2. 输入被设置为不同的名称,这里的输入名称是“title”,这也是箭头函数中返回的数据应该被引用的方式

    async addItem(){
        let addItem = await this.alertCtrl.create({
          header: 'Add a Task',
          message: 'Please enter a Task',
          inputs: [{
             name: 'title',
             type: 'text'
          }],
          buttons:[{
            text: 'Cancel',
            role: 'cancel'
          },{
            text: 'Add Task',
            handler: data => {
    
              let newTaskRef = this.taskList.push(
                { id: '', title: data.title, status: 'open' }
                );
                newTaskRef.update( { id: newTaskRef.key } );
    
            }
          }]
        })
    
        await addItem.present();
      }
    

    【讨论】:

    • 现在允许提交警报,但添加的任务仍未出现在列表中。有什么建议吗?
    • 您检查过您的 Firebase 权限和数据库规则吗?
    • 这些是规则,应该设置为true而不是false?
    • service cloud.firestore { match /databases/{database}/documents { match /{document=**} { 允许读,写:如果为假; } } }
    • 是的,或者你可以这样做:如果你服务于 cloud.firestore { match /databases/{database}/documents { match /{document=**} { 允许读取,写入; } } }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    • 2017-10-02
    • 1970-01-01
    • 2020-11-30
    • 2020-02-20
    • 2019-01-06
    • 1970-01-01
    相关资源
    最近更新 更多