Newt で特定のフィールドの値を取得する
Created on
投稿一覧ページでは必要なデータは限られる。例えば、投稿のスラッグとタイトルのみとか。
Newt を使っている場合、 getContents() に渡すパラメータの中の query.select を使って取得するフィールドを選択できる。 string[] を渡せる。
import { newtClient } from '../lib/newt'
import type { Article } from '../lib/newt'
const { items: articles } = await newtClient.getContents<Article>({
appUid: 'blog',
modelUid: 'article',
query: {
select: ['title', 'slug'],
},
})select 以外にも order, limit, skip, depth, or, and などが使える。詳しくは Newt-Inc/newt-client-js: JavaScript client for Newt. を参照。
参考