我正在使用Plastiq构建一个小网站。
我点击按钮时会触发一个事件。该事件返回一个promise,当它结算时,会更新模型。
我遇到的问题是视图在模型发生时不会更新。如果我再次单击该按钮(再次触发该事件),则视图会更新。
以下是一些演示此问题的代码:
/** @jsx plastiq.jsx */
var plastiq = require('plastiq');
var http = require('httpism');
class App {
constructor() {
this.apiKey = '...';
this.forecast = {};
}
getForecast() {
return http.get(`http://api.openweathermap.org/data/2.5/weather?q=${this.city}&appid=${this.apiKey}`)
.then((response) => {
this.forecast = response.body;
})
}
render() {
return <div>
<h1>Weather</h1>
<input type='text' binding={[this, 'city']} />
<button onclick={() => { this.getForecast() } }>Get forecast</button>
<div>
{ this.forecast.wind }
</div>
</div>;
}
}
plastiq.append(document.body, new App());
如何在第一次点击按钮时让视图更新?
由于
答案 0 :(得分:2)
您的点击回调应该会返回承诺,以便重新渲染Plastiq。
转过来:
import cx_Oracle
import json
connection = cx_Oracle.Connection("TEST_3D/limo1013@10.40.33.160:1521/sdetest")
cursor = connection.cursor()
cursor.execute("""SELECT a.id AS building_nr, c.Geometry AS geometry, d.Classname AS polygon_typ FROM building a, THEMATIC_SURFACE b, SURFACE_GEOMETRY c, OBJECTCLASS d WHERE a.grid_id_400 = 4158 AND a.id = b.BUILDING_ID AND b.LOD2_MULTI_SURFACE_ID = c.ROOT_ID AND c.GEOMETRY IS NOT NULL AND b.OBJECTCLASS_ID = d.ID""")
obj = cursor.fetchone()
obj = obj[1]
print obj
result = cursor.callfunc('sdo2geojson', cx_Oracle.OBJECT, [obj])
进入这个:
onclick={() => { this.getForecast() }}