使用 kintone.Promises(已棄用)

information

本頁面使用機器翻譯而成。
機器翻譯免責聲明 (External link)

目錄

瀏覽器的 Promise (External link) 在 cybozu.com 支援的所有 Web 瀏覽器中都可用。
我們建議您不要使用 kintone.Promise,而應使用瀏覽器 Promise。

使用 kintone.Promise

kintone.Promise 是使用Promise物件的kintone JavaScript API。
kintone.Promise 允許您在不支援 Promise 的瀏覽器(如 Internet Explorer 11)中使用 Promise。

函數

kintone.Promise(executor)

參事

參數名稱 類型 必須 說明
executor 函數 必須 傳遞給 Promise 對象的異步函數
executor 參數傳遞兩個函數:
  • resolve:在執行器中,操作成功時調用的函數
    傳遞給 resolve 函數的值可以作為 then 方法的第一個參數接收。
  • reject:在執行器中,操作失敗時調用的函數
    傳遞給 reject 函數的值可以作為 then 方法的第二個參數接收,也可以在 catch 方法中接收。

then 和 catch 方法準照 MDN Web Docs | Promise (External link)

返回值

kintone.Promise 物件

可支援的事件

記錄清單事件
記錄詳情事件
新增記錄事件
記錄編輯事件
記錄列印畫面事件
圖表事件
入口網站顯示事件

示例代碼

使用 發送 kintone REST API 請求的 API 發送請求
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
const body = {
  app: 1,
  id: 1
};

kintone.events.on('app.record.create.submit', (event) => {
  const record = event.record;
  return new kintone.Promise((resolve, reject) => {
    kintone.api(kintone.api.url('/k/v1/record.json', true), 'GET', body).then((resp) => {
      record['單行文字方塊_1'].value = resp.record['單行文字方塊_1'].value;
      resolve(event);
    });
  });
});
不使用 發送 kintone REST API 請求的 API 發送請求
1
2
3
4
5
6
7
8
9
kintone.events.on('app.record.create.submit', (event) => {
  const record = event.record;
  return new kintone.Promise((resolve, reject) => {
    setTimeout(() => {
      record['單行文字方塊_1'].value = 'sample';
      resolve(event);
    }, 10000);
  });
});