请教高手有没有从前端代码反向知晓服务器API接口的数据结构之法
因为只有小程序前端代码,无后端。前端基本逻辑是通过组件calendar.js及其servive.js请求数据,然后index.js获取。已知返回基本数据结构是json(code,data,message)格式,后端自己写个接口获取数据不难,但获得的数据好像不是index.js想要的,不知道有没有前端熟悉一点的大哥能帮忙看一下。
index.js
signEvent: function signEvent(_ref) {
var detail = _ref.detail;
this.setData({
page_type: "day"
});
var data = detail.data;
console.log(data);//打印不出数据来
if (!(data.activity instanceof Array)) {
var arr = new Array();
arr.push(data.activity);
data.activity = arr;
}
if (!(data.notes instanceof Array)) {
var _arr = new Array();
_arr.push(data.notes);
data.notes = _arr;
}
var other_arr = {};
if (data.other.list) {
data.other.list.forEach(function(data) {
if (!other_arr[data.name]) {
other_arr[data.name] = [];
}
other_arr[data.name].push(data);
});
}
var list_Arr = [ {
name: "会议活动",
data: data.activity,
type: "activity"
} ];
Object.keys(other_arr).forEach(function(key) {
list_Arr.push({
name: key,
data: other_arr[key],
type: "other"
});
});
calendar.js
dayInformation: function dayInformation(data) {
var _this3 = this;
if (this.data.day_sock) {
return;
}
this.data.day_sock = true;
setTimeout(function() {
if (_this3.data.day_sock) _this3.data.day_sock = false;
}, 5e3);
service.dayInformation(data, function(res) {
_this3.data.day_sock = false;
if (res.code == 1) {
_this3.triggerEvent("signEvent", {
data: res.data[data.calendarTime]
});
}
});
}
service.js
_createClass(calendarService, [ {
key: "dayInformation",
value: function dayInformation(data, cb) {
return new Promise(function(resolve) { api.request("api/calendar/CalendarInformation/dayInformation", data, "GET", function(res) {
resolve(res);
});
}).then(function(res) {
cb(res);
});
}
}
推荐文章: