如何使用纸对话聚合物元素?

时间:2014-11-19 11:00:12

标签: polymer material-design

我通过添加开始和结束标记<paper-dialog><p>This is it</p></paper-dialog>来使用该元素,但它没有显示出来。我是否需要在其上添加一些脚本以便在某些事件上触发它?或者是否有其他方法可以使其可见?

3 个答案:

答案 0 :(得分:17)

对话框本身是自动隐藏的。您通常使用按钮切换它。 例如,给对话框id="dialog"并按下on-tap="toggleDialog"按钮,这将是

toggleDialog: () => {
    this.$.dialog.toggle();
},

答案 1 :(得分:0)

<base href="https://polygit.org/polymer+polymer+v1.11.2/components/" />
<script src="webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="polymer/polymer.html" />
<link rel="import" href="paper-dialog/paper-dialog.html" />
<link rel="import" href="paper-input/paper-input.html" />
<link rel="import" href="paper-button/paper-button.html" />

<!--Here, we use a input field to give input to the dialog box-->  
<paper-input label="Name" id="username" always-float-label allowed-pattern="[a-zA-Z]" value={{username}} required error-message="User Name Required"></paper-input>

   <!--The button is used to submit the values-->

   <paper-button class="green" on-tap="validatedetails">Submit</paper-button>

   <!--Dialog is usually hidden. So by using id we can call the dialog box-->
   <div>
     <paper-dialog id="userdetails">

     <!--This section is used to fetch the input from the input-field and display on the dialog using one-way data binding-->

     <h2>User Information</h2>
       <p>[[username]]</p>

       <div class="buttons">

       <!--This button is used to close the dialog-->


       <paper-button dialog-dismiss style="color: #0B746E" on-tap="cleardata">CLOSE</paper-button>
     </div>
   </paper-dialog>
 </div>

 <script>
   Polymer({
     is: 'paper-dialog',
     properties: {
       username: {
         type: String,
       },

       <!--This function is used to call the dialog-->

       validatedetails: function() {
         this.$.userdetails.open();
       },
      });
  </script>

答案 2 :(得分:0)

对于聚合物3.0,我创建了paper-dialog,以从列表中删除具有标题,描述和两个按钮的项目。

<paper-dialog id="dialogDelete" >
    <h2>Delete</h2>
    <p>Are yout sure you want to delete this catalog?.</p>
    <div class="buttons">
        <paper-button dialog-dismiss>Cancel</paper-button>
        <paper-button dialog-confirm autofocus on-tap="_attempDeleteCatalog">Delete</paper-button>
    </div>
</paper-dialog>

要调用此对话框,我唯一要做的就是在函数中按其ID调用它,如下所示。

this.$.dialogDelete.open()

希望对您有帮助。