[英]How to query data from Firebase Realtime DB if the key has multiple words?
因此,javascript為您提供了兩種獲取對象屬性的方法:點表示法( course.Career
)或方括號( course["Career"]
)。
使用第二個鍵,您將得到非標准的鍵。 這是一個示例(請注意,我只是創建一個對象並使用該對象,而不是從FireBase中獲取,但是原理是相同的):
let course = { "id": 7290, "Career": "UGRD", "Catalog": 402, "Class Units": 3, "Component Code": "LEC", "Component Descr": "Lecture", "Course ID": "031564", "Equivalent Courses": "SOCI 402", "Long Title": "CONTEMPORARY SOCIOLOGY", "Pre Requisite Description": "Prereq: SoCI 302", "Subject": "SOCI" }; /** * The first option below uses dot notation, as you have * used in your current code. **/ console.log("Dot notation, Career: "+course.Career); /** * The second one uses brackets to get to the object key. * doing this, we can have names that are more non-standard. **/ console.info("Brackets, Class Units: "+course['Class Units'])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.