2016-03-25 24 views
0
<dom-module id="payment-list"> 
    <template> 
    <template is="dom-repeat" items="{{clients}}"> 
    <paper-item> 
     <span>{{item.Name}}</span> 
      &nbsp;|&nbsp; 
     <span>{{item.Amount}}</span> 
    </paper-item> 
    </template> 
    </template> 
     <script> 
     Polymer({ 
      is: 'payment-list', 
      properties: { 
      clients: { 
       notify:true, 
       type: Array, 
       value: [{Name:'A', Amount:'100'}, 
         {Name:'B', Amount:'200'}]   
      } 
      }, 
      handleComplete: function(NewValues){ 
      /***********/alert(NewValues);/***********/ 
      }, 
      ready: function(){ 
       google.script.run.withSuccessHandler(this.handleComplete).GS_GetClients(); 
      } 
     }); 
     </script> 
    </dom-module> 

私はgoogle.script.runを使用してGAS関数GS_GetClients()と通信しています。 GS_GetClientsはオブジェクトを返すので、この新しい値をプロパティ 'clients'にバインドしようとしています。 私はアラートを行うと、サーバー側のGAS関数から新しい値がhandleComplete関数に渡されることがわかります。しかし、私はプロパティ 'クライアント'に新しい値を割り当てることができません。ポリマーのプロパティ値へのサーバーの応答

this.clients = NewValuesを使用して値を設定することはできません。これは値を未定義にしています。

答えて

0

google.script.runの呼び出しは非同期です。

{{clients}}のレンダリングが既に起こっている場合、結果は返されているようです。

成功ハンドラhandleComplete(..)では、何らかの形でPolymerに再描画を指示する必要があります。

私は、ポリマーを知りませんが、あなたはこのようにそれを行うことができますかのようにドキュメントPolymer data bindingからそれはそうです:ここmember-functions説明されているポリマーでカスタムメソッドを呼び出す方法

Polymer({ 
    ... 
    setClients: function(clients) { 
    this.clients = clients; 
    // Notification required for binding to update! 
    this.notifyPath('clients', this.clients); 
    } 
}); 

は、申し訳ありませんが、よりを提供することはできませんポリマーに関する詳細な答え。

+0

しかし、どのように 'クライアント'に 'NewValues'を割り当てますか?プロパティ 'clients'はhandleComplete関数内ではアクセスできません。私が 'handleComplete'の内側に 'clients'を記録すると、結果は未定義となります。 –

関連する問題