JavaScriptの「Promise」とは
[Reference url]Javascript非同期含むループ
Javascript非同期含むループ
[Reference url]Javascript非同期promise
Javascript非同期promise
// 1. `new Promise()` して新しい `Promise` オブジェクトを作成
const p = new Promise((resolve, reject) => {
// 3. 非同期処理実行
setTimeout(() => {
// 4. 完了時に `resolve()` を実行
const result = 123;
resolve(result);
}, 1000);
});
// 2. `Promise` オブジェクトに `then()` でコールバックを登録
p.then((result) => {
// 5. `resolve()` に与えた情報を伴ってコールバック実行
console.log(result)
});
[Reference url]Javascript Remoting で Async/Await 例
Javascript Remoting で Async/Await 例
https://qiita.com/hrk623/items/30b89575c1478eeced37
<apex:page controller="AsyncAwaitSampleController">
<script>
(async () => {
let accountList = await getAccountList().catch(err => {console.error(err.message); });
if (accountList) { // エラー時は undefined となるので注意
console.log(accountList);
}
})();
const REMOTEACTION_OPTIONS = {buffer: true, escape: true, timeout: 120000};
function getAccountList() {
return new Promise((resolve, reject) => {
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.AsyncAwaitSampleController.getAccountList}',
(result, event) => {
if (event.status) resolve(result);
else reject(event);
}, this.REMOTEACTION_OPTIONS); // アロー関数を使う場合は this を忘れずに
});
}
</script>
</apex:page>
public class AsyncAwaitSampleController {
@RemoteAction
public static List<Account> getAccountList() {
return [SELECT Id, Name FROM Account];
}
}
[Javascript]Javasriptでyesterday取得
Javasriptでyesterday取得
var now = new Date();
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
[Javascript]Javasriptでtoday取得
Javasriptでtoday取得
const today = new Date();
const yyyy = today.getFullYear();
let mm = today.getMonth() + 1;
let dd = today.getDate();
const yyyymmdd = yyyy + "," + mm + "," + dd;
console.log('yyyymmdd:'+yyyymmdd);
var startDate = new Date(yyyymmdd);
console.log('startDate:'+startDate);
[Javascript]Javasriptでtomorrow取得
Javasriptでtomorrow取得
const today = new Date();
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
const yyyyTomorrow = tomorrow.getFullYear();
let mmTomorrow = tomorrow.getMonth() + 1;
let ddTomorrow = tomorrow.getDate();
const yyyymmddTomorrow = yyyyTomorrow + "," + mmTomorrow + "," + ddTomorrow;
console.log('yyyymmddTomorrow:'+yyyymmddTomorrow);
var endDate = new Date(yyyymmddTomorrow);
console.log('endDate:'+endDate);
[Firebase]クエリでendAt使用例
クエリでendAt使用例
const today = new Date();
const yyyy = today.getFullYear();
let mm = today.getMonth() + 1;
let dd = today.getDate();
const yyyymmdd = yyyy + "," + mm + "," + dd;
var startDate = new Date(yyyymmdd);
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1);
const yyyyTomorrow = tomorrow.getFullYear();
let mmTomorrow = tomorrow.getMonth() + 1;
let ddTomorrow = tomorrow.getDate();
const yyyymmddTomorrow = yyyyTomorrow + "," + mmTomorrow + "," + ddTomorrow;
console.log('yyyymmddTomorrow:'+yyyymmddTomorrow);
var endDate = new Date(yyyymmddTomorrow);
console.log('endDate:'+endDate);
firebase.firestore()
.collectionGroup("samplecollection")
.orderBy("createdAt", "asc").startAt(startDate).endAt(endDate)
.limit(10)
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
console.log('success');
}, (error) => {
console.log('error');
});
})
[Reference url]Javasriptでtomorrow取得
Javasriptでtomorrow取得
https://flaviocopes.com/how-to-get-tomorrow-date-javascript/
[Javascript]mapでkeyを変数値にする方法
mapでkeyを変数値にする方法
const key = "age"
const value = "10"
const result = {[key]:value}
console.log(result)