#1 Use the 2sxc JS API to get Data
The samples can differ based on your Razor base class or if you're running an old version.
Selected: Typed (2sxc 16+) Switch to Dynamic (Razor14 or below)
Selected: Typed (2sxc 16+) Switch to Dynamic (Razor14 or below)
Requirements
Use the 2sxc JS API to get Data
This page uses the sxc data API to get data from the backend and display it in a table with JavaScript.
In this tutorial you'll learn how to:
- Create a
$2sxc
object using the current Module Id - Use the correct data source using
.data()
- Read data using the
.getOne(id)
query method - Read data using the
.getAll()
query method
Look at the content below to see the effect.
Name | Birthdate | Poems |
---|
This page uses the sxc data API to get data from the backend and display it in a table with JavaScript.
In this tutorial you'll learn how to:
- Create a $2sxc object using the current Module Id
- Create a Query service using the
.query(...)
. - Read data using
getAll()
,getStream(...)
andgetStreams(...)
Note that this sample will run the query RandomAuthorWithBooks
. There are some things which you should know:
- The Query has permissions configured to allow viewers to use the query in JS.
- Each call returns a random author with his books, so sometimes the books-list may be empty
⬇️ Result | Source ➡️
This page uses the sxc data API to query data from the backend using parameters and display it in a table with JavaScript.
In this tutorial you'll learn how to:
- Create a $2sxc object using the current Module Id
- Create a Query service using the
.query(...)
. - Add Parameters to the
.getAll(...)
,.getStream(...)
and.getStreams(...)
query methods through object or string
Note that this sample will run the query AuthorsWithBooks
.
#1 Use the 2sxc JS API to get Data