我遇到了这样的问题,有人知道如何解决吗? Xcode 11.2,SwiftUI
.onAppear(perform: self.sessionChat.loadMsgInChatRoom(chatRoom: chatRoom)) //then an error
func loadMsgInChatRoom(chatRoom: String) {
let db = Firestore.firestore()
db.collection("chatRoom").document(chatRoom).collection("msg")
.addSnapshotListener { (querySnapshot, err) in
if err != nil {
print((err?.localizedDescription)!)
return
}
for i in querySnapshot!.documentChanges {
if i.type == .added {
let user = i.document.get("user") as! String
let msg = i.document.get("msg") as! String
let idUser = i.document.get("idUser") as! String
let dateMsg = i.document.get("dateMsg") as! String
let id = i.document.documentID
self.msgs.append(dataMessges(id: id, user: user, msg: msg, idUser: idUser, dateMsg: dateMsg))
}
}
}
}
答案 0 :(得分:1)
public get singleStudent(): Student {
var studentId = this._dashboardService.selectedStudent.userID;
for (let i in this._dashboardService.account.students) {
if (this._dashboardService.account.students[i].userID == studentId)
return this._dashboardService.account.students[i]
}
}
闭包了,所以我认为需要大括号
<div class="studentmenu-2-0">
<ul class="nav align-items-center justify-content-md-start justify-content-between" *ngIf="account && students">
<li class="col-9 col-xl-auto col-lg-10 col-md-9">
<div class="{{singleStudent==selectedStudent && highlightStudent?'hoveffect':''}}">
<div class="student_info">
<div class="media">
<span class="d-inline student-photo mr-1"><a (click)="setStudent(singleStudent)"><img [src]="singleStudent.imageUrl ? getStudentFaceImage(singleStudent.imageUrl):tempDpImage" /></a></span>
<div class="media-body align-self-center">
<span class="d-inline student-name mr-1"><a (click)="setStudent(stud)"><span>{{singleStudent.firstName}}</span>,</a></span>
<span class="d-inline student-class mr-1">{{singleStudent.className}} - {{ singleStudent.sectionName}},</span>
<span class="d-inline student-school mr-1">{{singleStudent.schoolName}}</span>
<span class="d-inline student-school mr-1">{{singleStudent.schoolId}}</span>
<span class="d-inline student-photos" *ngIf="!isHeartsOnly"><i>({{(selectedStudent.photos && selectedStudent.photos.list)?selectedStudent.photos.list.length:0}} photos)</i></span>
</div>
</div>
</div>
</div>
</li>
<li class="col-3 col-md-auto ml-md-2">
<div class="hovlink">
<a (click)="AddNewKidPopup()" class="playBut"><span class="d-inline" style="position: relative;"><svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/" x="0px" y="0px" width="28px" height="28px" viewBox="0 0 213.7 213.7" enable-background="new 0 0 213.7 213.7" xml:space="preserve"><circle class="circle" id="XMLID_17_" fill="none" stroke-width="7" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" cx="106.8" cy="106.8" r="103.3"></circle> </svg><img src="//res.cloudinary.com/klassaktcontent/image/upload/v1534852393/klassakt/svg/plus.svg" /></span><span class="add-image-text">Add kids</span></a>
</div>
</li>
</ul>
</div>
或更简单的方法:
.onAppear