@adapt-retail/banner-data 中文文档教程
@adapt-retail/banner-data (alpha)
用于与 Adapt 零售
api
通信的 JavaScript api。???? 警告:该项目处于 alpha 阶段。 谨慎使用。 ????????
Install
NPM
npm install @adapt-retail/banner-data
YARN
yarn add @adapt-retail/banner-data
API
Create object
创建 AdaptData 时提供适应数据。
注意:在创建您的第一个 Adapt
Banner
或InstoreTV
时 我们建议您使用collection
制作而不是Banner
或InstoreTV
制作。 这是因为您无法生成未分配模板的Banner
或InstoreTV
作品的预览。 通常您在创建Adapt Template
时不需要它。
// Import Adapt Data
import AdaptData from '@adapt-retail/banner-data';
// Create instance
var adapt = new AdaptData({
account: 'priceco58c12436f20b4', // Account key
project: 1, // Project ID
campaign: 1, // Campaign ID
production: 1, // Production ID
source: null, // optional
preview: false, // optional
});
Live vs Preview
设置预览 preview: true
将使用较慢但较快的数据重新加载。 对于实时站点,请确保使用 preview: false
以使用我们的快速 CDN,并在 5 分钟内重新加载缓存。
Set custom datasource
设置 Adapt 数据的源属性将覆盖 api 请求的任何数据。 这对于离线开发非常有用。
var adapt = new AdaptData({
source: {
data: [
{
id: 1234,
name: 'Product',
price: 199
}
]
}
});
Start
设置对象后,您可以调用 .start
开始检索内容。
var adapt = new AdaptData({ ... });
// Via promise
adapt.start().then( function( adapt_data ) {
... Adapt data is loaded and ready ...
} );
// Via function parameter
adapt.start( function( adapt_data ) {
... Adapt data is loaded and ready ...
} );
Asset
在 adapt 文件夹中获取资产。
adapt.start( function( adapt_data ) {
adapt.asset( 'my-image.png' );
} );
LightAdaptData
Light adapt data 是 adapt data 的超轻量级版本。 它不能从外部源请求数据,但它可以读取source
。
此类适用于 Adapt 横幅制作。
使用 webpack 时,您可以在运行生产脚本时设置此设置。
if (process.env.NODE_ENV === 'production') {
module.exports.resolve = {
alias: {
'@adapt-retail/banner-data': '@adapt-retail/banner-data/dist/LightAdaptData.js',
}
};
}
@adapt-retail/banner-data (alpha)
JavaScript api for communicating with Adapt retail
api
.???????? Warning: This project is in alpha stage. Use with caution. ????????
Install
NPM
npm install @adapt-retail/banner-data
YARN
yarn add @adapt-retail/banner-data
API
Create object
Provide the adapt data when creating the AdaptData.
Note: When creating your first Adapt
Banner
orInstoreTV
We recommend that you use acollection
production instead of aBanner
orInstoreTV
production. This is because you cannot generate preview of aBanner
orInstoreTV
production that do not have template assign to it. And usually you do not have that when creating yourAdapt Template
.
// Import Adapt Data
import AdaptData from '@adapt-retail/banner-data';
// Create instance
var adapt = new AdaptData({
account: 'priceco58c12436f20b4', // Account key
project: 1, // Project ID
campaign: 1, // Campaign ID
production: 1, // Production ID
source: null, // optional
preview: false, // optional
});
Live vs Preview
Setting preview preview: true
will use the slower but faster reloading of data. For live sites, make sure to use the preview: false
to use our fast CDN with cache reload in 5 minutes.
Set custom datasource
Setting the source property of the Adapt data will overwrite any data requested by api. This is nice for developing when you are offline.
var adapt = new AdaptData({
source: {
data: [
{
id: 1234,
name: 'Product',
price: 199
}
]
}
});
Start
After setting up the object, you can call .start
to start retrieving the content.
var adapt = new AdaptData({ ... });
// Via promise
adapt.start().then( function( adapt_data ) {
... Adapt data is loaded and ready ...
} );
// Via function parameter
adapt.start( function( adapt_data ) {
... Adapt data is loaded and ready ...
} );
Asset
Get the asset in the adapt folder.
adapt.start( function( adapt_data ) {
adapt.asset( 'my-image.png' );
} );
LightAdaptData
Light adapt data is a super light version for adapt data. It cannot request data from external source, but it can read source
.
This class is meant for Adapt banner productions.
When using webpack you can set this setting when running production script.
if (process.env.NODE_ENV === 'production') {
module.exports.resolve = {
alias: {
'@adapt-retail/banner-data': '@adapt-retail/banner-data/dist/LightAdaptData.js',
}
};
}