Class Properties

พร็อพเพอร์ตี้

ออบเจ็กต์พร็อพเพอร์ตี้จะทําหน้าที่เป็นอินเทอร์เฟซในการเข้าถึงพร็อพเพอร์ตี้ผู้ใช้ เอกสาร หรือสคริปต์ ประเภทพร็อพเพอร์ตี้เฉพาะจะขึ้นอยู่กับเมธอด 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ตั้งค่าคู่คีย์-ค่าทั้งหมดจากออบเจ็กต์ที่ระบุใน Store 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');

พารามิเตอร์

ชื่อTypeคำอธิบาย
keyStringคีย์สำหรับพร็อพเพอร์ตี้ที่จะลบ

รีเทิร์น

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 ปัจจุบัน โปรดทราบว่าออบเจ็กต์ที่แสดงผลไม่ใช่ฟีเจอร์ดูภาพสดของ Store ดังนั้น การเปลี่ยนพร็อพเพอร์ตี้ในออบเจ็กต์ที่ส่งกลับจะไม่อัปเดตพร็อพเพอร์ตี้เหล่านั้นในพื้นที่เก็บข้อมูลโดยอัตโนมัติ หรือในทางกลับกัน

// 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);

พารามิเตอร์

ชื่อTypeคำอธิบาย
keyStringคีย์สำหรับค่าคุณสมบัติเพื่อดึงข้อมูล

รีเทิร์น

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);

พารามิเตอร์

ชื่อTypeคำอธิบาย
propertiesObjectออบเจ็กต์ที่มีคู่คีย์-ค่าที่จะตั้งค่า

รีเทิร์น

Properties — ร้าน Properties นี้สำหรับการทำเชน


setProperties(properties, deleteAllOthers)

ตั้งค่าคู่คีย์-ค่าทั้งหมดจากออบเจ็กต์ที่ระบุใน Store 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);

พารามิเตอร์

ชื่อTypeคำอธิบาย
propertiesObjectออบเจ็กต์ที่มีคู่คีย์-ค่าที่จะตั้งค่า
deleteAllOthersBooleantrue เพื่อลบคู่คีย์-ค่าอื่นๆ ทั้งหมดในออบเจ็กต์พร็อพเพอร์ตี้ false ไม่ใช้

รีเทิร์น

Properties — ร้าน Properties นี้สำหรับการทำเชน


setProperty(key, value)

ตั้งค่าคู่คีย์-ค่าที่ระบุในสโตร์ Properties ปัจจุบัน

// Sets the user property 'nickname' to 'Bobby'.
var userProperties = PropertiesService.getUserProperties();
userProperties.setProperty('nickname', 'Bobby');

พารามิเตอร์

ชื่อTypeคำอธิบาย
keyStringคีย์สำหรับพร็อพเพอร์ตี้
valueStringค่าที่จะเชื่อมโยงกับคีย์

รีเทิร์น

Properties — ร้าน Properties นี้สำหรับการทำเชน