2015-04-12 41 views
0

的行爲假設我有三個選項卡在一起,在每個選項卡的內容通過core-ajax奇怪的聚合物數據伺機

 <core-ajax auto url="http://example.com/tab.json" handleAs="json" 
response="{{response}}"></core-ajax> 


<paper-tabs id="tabs" selected="{{response[0].name}}" flex > 
       <template repeat="{{mytab as t}}"> 
       <paper-tab name="{{t.name}}">{{t.name}}</paper-tab> 
       </template> 
</paper-tabs> 




Polymer({ 
     responseChanged:function(response){ 
     this.mytab= this.response; 
     console.log(this.mytab[0].name); 
     } 
    }); 

代碼獲取上述顯示正常,但什麼是困惑我的是,當我點擊其他除第一個選項卡外的兩個選項卡,第一個選項卡名稱(即內容)相應地改變爲哪個選項卡被點擊的名稱。我不能得到這個,任何人都可以向我解釋?

感謝

回答

0

我找到一個解決方案來解決這個問題,但我不知道這是正確的做法或最佳:

<core-ajax auto url="http://example.com/tab.json" handleAs="json" 
response="{{response}}"></core-ajax> 

            (changed) 
<paper-tabs id="tabs" selected="{{defaulttab}}" flex > 
       <template repeat="{{mytab as t}}"> 
       <paper-tab name="{{t.name}}">{{t.name}}</paper-tab> 
       </template> 
</paper-tabs> 




Polymer({ 
     responseChanged:function(response){ 
     this.mytab= this.response; 
     this.defaulttab = this.response[0].name;(added) 
     console.log(this.mytab[0].name); 
     } 
    }); 

可正常工作。