2016-03-25 27 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 data binding看來,如果你能做到這一點是這樣的:

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

如何調用Polymer自定義方法在這裏member-functions解釋,抱歉不能提供更多關於Polymer的詳細答案。

+0

但是,如何將'NewValues'分配給'客戶'。屬性'clients'在handleComplete函數內部是不可訪問的。如果我在'handleComplete'內部給'客戶'註冊,它會給出未定義的結果。 –