Newt で特定のフィールドの値を取得する
Published Feb 25, 2025
⋅
Updated Mar 15, 2025
dependency
"newt-client-js": "^3.3.8"
投稿一覧ページでは必要なデータは限られる。例えば、投稿のスラッグとタイトルのみとか。
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. を参照。
参考