2016-07-18 7 views
1

私はPlastiqを使用して小さなサイトを構築しています。Plastiqは2番目のレンダリングまでビューを更新しません

ボタンをクリックすると、私はイベントが発生します。イベントは約束を返し、解決するとモデルを更新します。

私が抱えている問題は、モデルが表示されてもビューが更新されないということです。もう一度ボタンをクリックすると(イベントが再開されます)、ビューは更新されます。ここで

がある問題を示し、いくつかのコード:

/** @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()); 

どのように私はボタンがクリックされた最初の時間を更新するためのビューを得ることができますか?

おかげ

答えて

2

は、あなたのクリックコールバックは、再レンダリングにplastiqための約束を返す必要があります。この中へ

onclick={() => { this.getForecast() }} 

onclick={() => this.getForecast() } 

はこれを回し

関連する問題