遵循MVC結構,使用模板語法。Controller調用Model中查詢數據庫的方法,經過display函數把數據注入View,View經過模版語法解析數據sql
{% if event.length==0 %}
<li>
<div class="nodata">暫無數據</div>
</li>
{%- endif %}
{% for i in event -%}
<li>
<span class="td e-1">{{i.time|default('- -',true)}}</span>
<span class="td e-2">{{i.country}}</span>
<span class="td e-3">{{i.city|default('- -',true)}}</span>
<span class="td e-4">
{% for j in range(0,5) -%}
{% if loop.index <=i.importance %}
<img src="images/download/x1.png" >
{% else %}
<img src="images/download/x2.png" >
{% endif %}
{%- endfor %}
</span>
<span class="td e-5">
<span>{{i.event}}</span>
</span>
</li>
{% endfor %}
複製代碼
let date=this.get("id");
let data=[],data2=[],data3=[],time="",count={},lastDay={};
if(util.strDateTime(date)){
data2 = await this._calendar.get_event(date);
}
this.assign('event', data2);
return this.display("calendar");
複製代碼
module.exports = class extends think.Model {
//查詢財經大事件
async get_event(date, star, country) {
//jujin8_economic_event
var condition2 = "";
if (!date) {
condition2 = "DATE(date) = CURRENT_DATE";
}
else {
condition2 = "DATE(date) = DATE('" + date + "')";
}
if (star) {
condition2 += " AND importance>=" + star;
}
if (country) {
condition2 += " AND country=" + country;
}
var sql = "SELECT country,time,city,importance,event FROM economic_event " +
"WHERE " + condition2 + " ORDER BY created_at,country;";
var result = await this.query(sql);
return formatJson(result);
}
複製代碼
}數據庫