2016-08-04 44 views
0

試圖設計模板中的紙張按鈕樣式,我嘗試了不同的扇區,只有一個工作,所以我如何正確地進行樣式設計。 所以在我的index.html調用鐵AJAX元件和一個最後的響應我所說的DOM重複模板聚合物無法在重複模板中設置自定義標籤

<iron-ajax id="aj" auto 
       url="url" 
       handle-as="json" 
       last-response="{{ajaxResponse}}" 
       contentType="text/HTML" 
       debounce-duration="300"></iron-ajax> 
       <div class="video"> 
       <template is="dom-repeat" items="[[ajaxResponse]]" > 
        <paper-card image="[[item.fields.image]]"> 
         <feed-bdy items="[[item]]"></feed-bdy> 

和在饋bdy.html:

<link rel="import" href="../../bower_components/polymer/polymer.html"> 
<link rel="import" href="../../bower_components/paper-styles/typography.html"> 
<dom-module is="feed-bdy"> 
    <style > 
    :host{ 
    --paper-button-ink-color: var(--paper-pink-a200); 
    paper-button.custom:hover{ background-color: var(--paper-indigo-100)  !import; } 
    } 
    :host paper-button.rea:hover{ 
    --paper-button-ink-color: var(--paper-pink-a200); 
    color: red 
    } 
    --paper-button.custom:hover { 
    background-color: var(--paper-indigo-100) !import; 
    color: white !important; 
    } 
    paper-button:hover{ 
    background-color:red !important; 
    } 
</style> 
<template id="repeater" is="dom-repeat" items="{{items}}"> 
    <div class="card-content"> 
    <div class="ar-header"> 
     <h3><a href="#"> [[items.fields.title]]</a></h3> 
    </div> 
    <div class="content-bdy"></div> 
    </div> 
    [[_renderHTML(items)]] 
    <div class="card-actions"> 
    <paper-button class="custom">إقراء المزيد !</paper-button> 
    <paper-button> 
     شارك 
     <iron-icon icon="reply"></iron-icon> 
    </paper-button> 
    </div> 
</template> 
<script> 
    Polymer({ 
    is: 'feed-bdy', 
    properties: { 
     artId:{ 
     type : String, 
     observer: '_renderHTML' 

     } 
    }, 
    listeners :{ 

    }, 
    _renderHTML: function(items) { 
    // firstp to get only the first pargarph to put in the home page 
    var ss= items.fields.body; 
    //console.log(this.$$(".card-content")); 
    var firstp = ss.substring(0,ss.search("</p>")+4); 
    this.$$(".content-bdy").innerHTML += firstp; 


    }, 
    _toggle : function(e){ 
    var id = Polymer.dom(e).localTarget.title; 
    //console.log(id); 
    var moreInfo = document.getElementById(id); 
    // console.log(moreInfo); 
    var iconButton = Polymer.dom(e).localTarget; 
     iconButton.icon = moreInfo.opened ? 'hardware:keyboard-arrow-up' 
              : 'hardware:keyboard-arrow-down'; 
     moreInfo.toggle(); 
    } 
    }); 
</script> 
</dom-module> 
+0

你在'喂,bdy'代碼應該是裏面'template'標籤(包括'style'和'DOM-repeat')。聚合物僅將模板標籤內的HTML內容呈現到您的元素中。 – a1626

回答

0

有你的CSS的幾個問題:

  1. import!應該important!
  2. 混入和c ustom性質需要被選擇器內定義:

INCORRECT

<style> 
    --paper-button: { 
    /** Some styles */ 
    } 

    --paper-button-ink-color: blue; 
</style> 

CORRECT

<style> 
    :host { 
    --paper-button: { 
     /** Some styles */ 
    } 

    --paper-button-ink-color: blue; 
    } 
</style> 
  • 混入和自定義屬性不選擇器:
  • INCORRECT

    <style> 
        --paper-button.special-css-class { 
        /** Some styles */ 
        } 
    </style> 
    

    相反,可以使用.special-css-class作爲選擇器,並定義混入/自定義屬性進行匹配任何元素:

    CORRECT

    <template> 
        <style> 
        .special-css-class { 
         --paper-button: { 
         /** Some styles */ 
         } 
    
         --paper-button-ink-color: blue; 
        } 
        </style> 
    
        <paper-button class="special-css-class"></paper-button> 
    
        <!-- This button won't have your custom styles! --> 
        <paper-button></paper-button> 
    </template> 
    
  • 至少對於紙張按鈕,如果您只是想指定顏色和背景顏色,則不需要使用自定義屬性/ mixins:
  • <base href="https://polygit.org/components/"> 
     
    <script src="webcomponentsjs/webcomponents-lite.min.js"></script> 
     
    <link href="polymer/polymer.html" rel="import"> 
     
    <link href="paper-button/paper-button.html" rel="import"> 
     
    
     
    <x-foo></x-foo> 
     
    
     
    <dom-module id="x-foo"> 
     
        
     
        <template> 
     
        <style> 
     
         paper-button { 
     
         background-color: purple; 
     
         color: red; 
     
         } 
     
        </style> 
     
    
     
        <template is="dom-repeat" items="{{items}}"> 
     
         <paper-button>Click Me</paper-button> 
     
        </template> 
     
        </template> 
     
        
     
        <script> 
     
        Polymer({ 
     
         is: 'x-foo', 
     
         properties: { 
     
         items: { 
     
          value: [1, 2, 3, 4] 
     
         } 
     
         } 
     
        }); 
     
        </script> 
     
    </dom-module>

    +0

    編輯片段以包含':'! –

    +0

    最好將'style'標籤保留在'template'標籤內。儘管現在它可以工作,但它對性能有很大的影響,而Polymer可能會不贊成將來定義元素的這種方式 – a1626

    +0

    謝謝;相應更新! –

    相關問題