如何访问 Wix DB - 博客文章
How to get access to Wix DB - Blog Posts
所以现在我有一个主页,是使用 html 制作的。
我想添加一些 div,在其中显示我在 WIX 页面上发布的最新博客。
<div layout="row" layout-align="center center">
<md-card flex="60" class="pad-md md-body-1 border-1" md-colors="{"borderColor": "epprimary1-500", "color": "epsecondary6"}">
{{blog headline}}
<a href="{{blog link}}">Open Blog<md-icon>open_in_new</md-icon></a>
</md-card>
</div>
在 Wix 平台上,我知道他们将数据存储在所谓的数据集中的什么位置:
现在我需要知道如何从我的其他网站访问这些数据。
我终于明白了!!
您可以通过http请求获取您需要的数据。
因此,首先,您需要在 Wix 的后端文件夹中添加一个 javascript 并将其命名为“http-functions.js”,删除其内容并添加以下代码。
注:get_blogEntry()是方法_函数名()
Blog/Posts是我用的数据库,你可以用wix上的任何数据库。
import {ok, notFound, serverError} from 'wix-http-functions';
import wixData from 'wix-data';
export function get_blogEntry() {
let options = {
"headers": {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
}
};
// query a collection to find matching items
return wixData.query("Blog/Posts")
.find()
.then( (results) => {
// matching items were found
if(results.items.length > 0) {
let itemOne = results.items[0];
let itemTwo = results.items[1];
options.body = {
"blogOneTitle": itemOne.title,
"blogOneUrl": "https://etaplus.energy" + itemOne.postPageUrl,
"blogTwoTitle": itemTwo.title,
"blogTwoUrl": "https://etaplus.energy" + itemTwo.postPageUrl
}
return ok(options);
}
})
// something went wrong
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
} );
}
在您的后端添加此代码后,您可以通过以下方式访问数据URL:
"https://YOURWEBSITEURL/_functions/blogEntry 或者你的函数名称是什么"
所以现在我有一个主页,是使用 html 制作的。 我想添加一些 div,在其中显示我在 WIX 页面上发布的最新博客。
<div layout="row" layout-align="center center">
<md-card flex="60" class="pad-md md-body-1 border-1" md-colors="{"borderColor": "epprimary1-500", "color": "epsecondary6"}">
{{blog headline}}
<a href="{{blog link}}">Open Blog<md-icon>open_in_new</md-icon></a>
</md-card>
</div>
在 Wix 平台上,我知道他们将数据存储在所谓的数据集中的什么位置:
现在我需要知道如何从我的其他网站访问这些数据。
我终于明白了!!
您可以通过http请求获取您需要的数据。 因此,首先,您需要在 Wix 的后端文件夹中添加一个 javascript 并将其命名为“http-functions.js”,删除其内容并添加以下代码。
注:get_blogEntry()是方法_函数名()
Blog/Posts是我用的数据库,你可以用wix上的任何数据库。
import {ok, notFound, serverError} from 'wix-http-functions';
import wixData from 'wix-data';
export function get_blogEntry() {
let options = {
"headers": {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
}
};
// query a collection to find matching items
return wixData.query("Blog/Posts")
.find()
.then( (results) => {
// matching items were found
if(results.items.length > 0) {
let itemOne = results.items[0];
let itemTwo = results.items[1];
options.body = {
"blogOneTitle": itemOne.title,
"blogOneUrl": "https://etaplus.energy" + itemOne.postPageUrl,
"blogTwoTitle": itemTwo.title,
"blogTwoUrl": "https://etaplus.energy" + itemTwo.postPageUrl
}
return ok(options);
}
})
// something went wrong
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
} );
}
在您的后端添加此代码后,您可以通过以下方式访问数据URL:
"https://YOURWEBSITEURL/_functions/blogEntry 或者你的函数名称是什么"