Class Properties

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

ออบเจ็กต์พร็อพเพอร์ตี้ทำหน้าที่เป็นอินเทอร์เฟซในการเข้าถึงพร็อพเพอร์ตี้ของผู้ใช้ เอกสาร หรือสคริปต์ ประเภทพร็อพเพอร์ตี้ที่เฉพาะเจาะจงจะขึ้นอยู่กับวิธีการใดใน 3 วิธีของ PropertiesService ที่สคริปต์เรียกใช้ ได้แก่ PropertiesService.getDocumentProperties(), PropertiesService.getUserProperties() หรือ PropertiesService.getScriptProperties() ระบบจะไม่แชร์พร็อพเพอร์ตี้ระหว่างสคริปต์ ดูข้อมูลเพิ่มเติมเกี่ยวกับประเภทพร็อพเพอร์ตี้ได้ที่ คำแนะนำเกี่ยวกับบริการพร็อพเพอร์ตี้

เมธอด

วิธีการประเภทการแสดงผลรายละเอียดแบบย่อ
deleteAllProperties()Propertiesลบพร็อพเพอร์ตี้ทั้งหมดในร้านค้า Properties ปัจจุบัน
deleteProperty(key)Propertiesลบพร็อพเพอร์ตี้ที่มีคีย์ที่ระบุในProperties store ปัจจุบัน
getKeys()String[]รับคีย์ทั้งหมดในที่เก็บข้อมูล Properties ปัจจุบัน
getProperties()Objectรับสำเนาคู่คีย์-ค่าทั้งหมดในProperties Store ปัจจุบัน
getProperty(key)Stringรับค่าที่เชื่อมโยงกับคีย์ที่ระบุในPropertiesที่เก็บnullปัจจุบัน หรือ null หากไม่มีคีย์ดังกล่าว
setProperties(properties)Propertiesตั้งค่าคู่คีย์-ค่าทั้งหมดจากออบเจ็กต์ที่ระบุในProperties store ปัจจุบัน
setProperties(properties, deleteAllOthers)Propertiesตั้งค่าคู่คีย์-ค่าทั้งหมดจากออบเจ็กต์ที่ระบุในที่เก็บ Properties ปัจจุบัน โดยอาจลบพร็อพเพอร์ตี้อื่นๆ ทั้งหมดในที่เก็บด้วย
setProperty(key, value)Propertiesตั้งค่าคู่คีย์-ค่าที่ระบุในProperties store ปัจจุบัน

เอกสารโดยละเอียด

deleteAllProperties()

ลบพร็อพเพอร์ตี้ทั้งหมดในร้านค้า Properties ปัจจุบัน

// Deletes all user properties.
const userProperties = PropertiesService.getUserProperties();
userProperties.deleteAllProperties();

รีเทิร์น

Properties — ร้านค้า Properties นี้สำหรับการเชื่อมโยง


deleteProperty(key)

ลบพร็อพเพอร์ตี้ที่มีคีย์ที่ระบุในProperties store ปัจจุบัน

// Deletes the user property 'nickname'.
const userProperties = PropertiesService.getUserProperties();
userProperties.deleteProperty('nickname');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
keyStringคีย์ของพร็อพเพอร์ตี้ที่จะลบ

รีเทิร์น

Properties — ร้านค้า Properties นี้สำหรับการเชื่อมโยง


getKeys()

รับคีย์ทั้งหมดในที่เก็บข้อมูล Properties ปัจจุบัน

// Sets several properties, then logs the value of each key.
const scriptProperties = PropertiesService.getScriptProperties();
scriptProperties.setProperties({
  cow: 'moo',
  sheep: 'baa',
  chicken: 'cluck',
});
const keys = scriptProperties.getKeys();
Logger.log('Animals known:');
for (let 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.
const scriptProperties = PropertiesService.getScriptProperties();
scriptProperties.setProperties({
  cow: 'moo',
  sheep: 'baa',
  chicken: 'cluck',
});

const animalSounds = scriptProperties.getProperties();

// Logs:
// A chicken goes cluck!
// A cow goes moo!
// A sheep goes baa!
for (const kind in animalSounds) {
  Logger.log('A %s goes %s!', kind, animalSounds[kind]);
}

รีเทิร์น

Object - สำเนาของคู่คีย์-ค่าทั้งหมดในร้านค้า Properties ปัจจุบัน


getProperty(key)

รับค่าที่เชื่อมโยงกับคีย์ที่ระบุในPropertiesที่เก็บnullปัจจุบัน หรือ null หากไม่มีคีย์ดังกล่าว

// Gets the user property 'nickname'.
const userProperties = PropertiesService.getUserProperties();
const nickname = userProperties.getProperty('nickname');
Logger.log(nickname);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
keyStringคีย์สำหรับค่าพร็อพเพอร์ตี้ที่จะดึงข้อมูล

รีเทิร์น

String - ค่าที่เชื่อมโยงกับคีย์ที่ระบุในPropertiesที่เก็บปัจจุบัน


setProperties(properties)

ตั้งค่าคู่คีย์-ค่าทั้งหมดจากออบเจ็กต์ที่ระบุในProperties store ปัจจุบัน

// Sets multiple user properties at once.
const userProperties = PropertiesService.getUserProperties();
const newProperties = {
  nickname: 'Bob',
  region: 'US',
  language: 'EN'
};
userProperties.setProperties(newProperties);

พารามิเตอร์

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

รีเทิร์น

Properties — ร้านค้า Properties นี้สำหรับการเชื่อมโยง


setProperties(properties, deleteAllOthers)

ตั้งค่าคู่คีย์-ค่าทั้งหมดจากออบเจ็กต์ที่ระบุในที่เก็บ Properties ปัจจุบัน โดยอาจลบพร็อพเพอร์ตี้อื่นๆ ทั้งหมดในที่เก็บด้วย

// Sets multiple user properties at once while deleting all other user
// properties.
const userProperties = PropertiesService.getUserProperties();
const newProperties = {
  nickname: 'Bob',
  region: 'US',
  language: 'EN'
};
userProperties.setProperties(newProperties, true);

พารามิเตอร์

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

รีเทิร์น

Properties — ร้านค้า Properties นี้สำหรับการเชื่อมโยง


setProperty(key, value)

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

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

พารามิเตอร์

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

รีเทิร์น

Properties — ร้านค้า Properties นี้สำหรับการเชื่อมโยง