The App / Module Sxc Instance
The module-specific sxc
-instance is the core JavaScript object helping you in these cases:
- if you want full control over the edit-experience with custom buttons etc.
- when you want to use view-data as an asyc-JS call
- if you wish to work with WebAPI REST calls - of your own App-WebApi, 2sxc-WebApi or Dnn-WebApi
How to use
First you must ensure that you have the $2sxc
global on your page, which will get you a module-specific sxc
.
Here's a simple example (assuming you have the $2sxc global):
<a onclick="var sxc = $2sxc(this); alert(sxc.isEditMode())">
click me
</a>
The code above shows
- how the sxc-object is retrieved using the
$2sxc(...)
global, based on the current contextthis
- how to ask if we're in edit-mode
Here's another quick example, calling a C# web-api endpoint:
var sxc = $2sxc(27);
sxc.webApi.post("Form/ProcessForm")
.success(function(result) {
// ....
});
How to Get the Current Context's sxc
Instance
Before you continue, make sure you know how to resolve/get your sxc
, as it is unique for each Dnn-Module.
This is because each action needs to know which module it belongs to.
Read about the 3 ways to get this in the $2sxc Global docs.
The API of an Module sxc
Instance
📖 Sxc
Common Tasks
- Work with the JSON Data of the Current Module
📖 In v.13+ you should should use the Data Service - Work with REST Api to Read/Write Content-Items / Data
📖 In v.13+ you should should use the Data Service
In older versions, use the Sxc WebApi - Use App-Queries with $2sxc
📖 In v.13+ you should should use the Query Service objects.
In older versions, use the Sxc WebApi - Work with Custom C# App WebAPIs
📖 Read about it in the Sxc WebApi page.
Demo App and further links
You should find some code examples in this demo App
- TimeLineJS
- all the JS-apps including AngularJS in the app-catalog
More links: Description of the feature on 2sxc docs
History
- Introduced in 2sxc 04.00
- Enhanced with
SxcData
andSxcQuery
in 2sxc 13.00