ออบเจ็กต์คุณสมบัติทําหน้าที่เป็นอินเทอร์เฟซสําหรับเข้าถึงพร็อพเพอร์ตี้ผู้ใช้ เอกสาร หรือสคริปต์ ประเภทพร็อพเพอร์ตี้ที่เจาะจงขึ้นอยู่กับ 3 วิธีที่ PropertiesService
เรียกใช้สคริปต์ ซึ่งได้แก่ PropertiesService.getDocumentProperties()
, PropertiesService.getUserProperties()
หรือ PropertiesService.getScriptProperties()
แชร์พร็อพเพอร์ตี้ระหว่างสคริปต์ไม่ได้ ดูข้อมูลเพิ่มเติมเกี่ยวกับประเภทพร็อพเพอร์ตี้ได้ที่คําแนะนําเกี่ยวกับบริการพร็อพเพอร์ตี้
เมธอด
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
---|---|---|
deleteAllProperties() | Properties | ลบพร็อพเพอร์ตี้ทั้งหมดในร้านค้า Properties รายการปัจจุบัน |
deleteProperty(key) | Properties | ลบพร็อพเพอร์ตี้ที่มีคีย์ที่ระบุในร้านค้า Properties ปัจจุบัน |
getKeys() | String[] | ดาวน์โหลดคีย์ทั้งหมดในร้านค้า Properties ปัจจุบัน |
getProperties() | Object | รับสําเนาของคู่คีย์-ค่าทั้งหมดในร้านค้า Properties ปัจจุบัน |
getProperty(key) | String | เรียกดูค่าที่เชื่อมโยงกับคีย์ที่ระบุในร้านค้า Properties ปัจจุบัน หรือ null หากไม่มีคีย์ดังกล่าว |
setProperties(properties) | Properties | ตั้งค่าคู่คีย์-ค่าทั้งหมดจากออบเจ็กต์ที่ระบุในร้านค้า Properties ปัจจุบัน |
setProperties(properties, deleteAllOthers) | Properties | ตั้งค่าคู่คีย์-ค่าทั้งหมดจากออบเจ็กต์หนึ่งๆ ในร้านค้า Properties ปัจจุบัน หรือจะเลือกลบพร็อพเพอร์ตี้อื่นๆ ทั้งหมดใน Store หรือไม่ก็ได้ |
setProperty(key, value) | Properties | ตั้งค่าคู่คีย์-ค่าที่ระบุในร้านค้า Properties ปัจจุบัน |
เอกสารประกอบโดยละเอียด
deleteAllProperties()
ลบพร็อพเพอร์ตี้ทั้งหมดในร้านค้า Properties
รายการปัจจุบัน
// Deletes all user properties. var userProperties = PropertiesService.getUserProperties(); userProperties.deleteAllProperties();
ไปกลับ
Properties
— ร้านค้า Properties
นี้สําหรับเชนธุรกิจ
deleteProperty(key)
ลบพร็อพเพอร์ตี้ที่มีคีย์ที่ระบุในร้านค้า Properties
ปัจจุบัน
// Deletes the user property 'nickname'. var userProperties = PropertiesService.getUserProperties(); userProperties.deleteProperty('nickname');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สําหรับพร็อพเพอร์ตี้ที่จะลบ |
ไปกลับ
Properties
— ร้านค้า Properties
นี้สําหรับเชนธุรกิจ
getKeys()
ดาวน์โหลดคีย์ทั้งหมดในร้านค้า Properties
ปัจจุบัน
// Sets several properties, then logs the value of each key. var scriptProperties = PropertiesService.getScriptProperties(); scriptProperties.setProperties({ 'cow': 'moo', 'sheep': 'baa', 'chicken': 'cluck' }); var keys = scriptProperties.getKeys(); Logger.log('Animals known:'); for (var i = 0; i < keys.length; i++) { Logger.log(keys[i]); }
ไปกลับ
String[]
— อาร์เรย์ของคีย์ทั้งหมดในร้านค้า Properties
ปัจจุบัน
getProperties()
รับสําเนาของคู่คีย์-ค่าทั้งหมดในร้านค้า Properties
ปัจจุบัน โปรดทราบว่าออบเจ็กต์ที่แสดงผลไม่ใช่มุมมองสดของร้านค้า ดังนั้นการเปลี่ยนคุณสมบัติในออบเจ็กต์ที่ส่งคืนจะไม่อัปเดตพื้นที่เก็บข้อมูลโดยอัตโนมัติหรือในทางกลับกัน
// Sets several script properties, then retrieves them and logs them. var scriptProperties = PropertiesService.getScriptProperties(); scriptProperties.setProperties({ 'cow': 'moo', 'sheep': 'baa', 'chicken': 'cluck' }); var animalSounds = scriptProperties.getProperties(); // Logs: // A chicken goes cluck! // A cow goes moo! // A sheep goes baa! for (var kind in animalSounds) { Logger.log('A %s goes %s!', kind, animalSounds[kind]); }
ไปกลับ
Object
— สําเนาคู่คีย์-ค่าทั้งหมดในร้านค้า Properties
ปัจจุบัน
getProperty(key)
เรียกดูค่าที่เชื่อมโยงกับคีย์ที่ระบุในร้านค้า Properties
ปัจจุบัน หรือ null
หากไม่มีคีย์ดังกล่าว
// Gets the user property 'nickname'. var userProperties = PropertiesService.getUserProperties(); var nickname = userProperties.getProperty('nickname'); Logger.log(nickname);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สําหรับค่าพร็อพเพอร์ตี้ในการดึงข้อมูล |
ไปกลับ
String
— ค่าที่เชื่อมโยงกับคีย์ที่ระบุในร้านค้า Properties
ปัจจุบัน
setProperties(properties)
ตั้งค่าคู่คีย์-ค่าทั้งหมดจากออบเจ็กต์ที่ระบุในร้านค้า Properties
ปัจจุบัน
// Sets multiple user properties at once. var userProperties = PropertiesService.getUserProperties(); var newProperties = {nickname: 'Bob', region: 'US', language: 'EN'}; userProperties.setProperties(newProperties);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
properties | Object | ออบเจ็กต์ที่มีคู่คีย์-ค่าเพื่อตั้งค่า |
ไปกลับ
Properties
— ร้านค้า Properties
นี้สําหรับเชนธุรกิจ
setProperties(properties, deleteAllOthers)
ตั้งค่าคู่คีย์-ค่าทั้งหมดจากออบเจ็กต์หนึ่งๆ ในร้านค้า Properties
ปัจจุบัน หรือจะเลือกลบพร็อพเพอร์ตี้อื่นๆ ทั้งหมดใน Store หรือไม่ก็ได้
// Sets multiple user properties at once while deleting all other user properties. var userProperties = PropertiesService.getUserProperties(); var newProperties = {nickname: 'Bob', region: 'US', language: 'EN'}; userProperties.setProperties(newProperties, true);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
properties | Object | ออบเจ็กต์ที่มีคู่คีย์-ค่าเพื่อตั้งค่า |
deleteAllOthers | Boolean | true เพื่อลบคู่คีย์-ค่าอื่นๆ ทั้งหมดในออบเจ็กต์พร็อพเพอร์ตี้ และ false ไม่ให้ |
ไปกลับ
Properties
— ร้านค้า Properties
นี้สําหรับเชนธุรกิจ
setProperty(key, value)
ตั้งค่าคู่คีย์-ค่าที่ระบุในร้านค้า Properties
ปัจจุบัน
// Sets the user property 'nickname' to 'Bobby'. var userProperties = PropertiesService.getUserProperties(); userProperties.setProperty('nickname', 'Bobby');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์ของพร็อพเพอร์ตี้ |
value | String | ค่าเพื่อเชื่อมโยงกับคีย์ |
ไปกลับ
Properties
— ร้านค้า Properties
นี้สําหรับเชนธุรกิจ