2017-09-07 80 views
0

嘗試刪除條目時,遇到聚合物和應用程序存儲問題。 我正在嘗試向Vaading Grid添加一個按鈕,該按鈕將刪除設置按鈕的條目。 唯一的是我似乎無法使它工作,當我點擊按鈕,甚至console.log不起作用。我在這裏做錯了什麼?聚合物和應用程序存儲:刪除條目按鈕

下面是代碼:

<!-- 
@license 
Copyright (c) 2016 The Polymer Project Authors. All rights reserved. 
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt 
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt 
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt 
Code distributed by Google as part of the polymer project is also 
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt 
--> 

<link rel="import" href="../bower_components/polymer/polymer-element.html"> 
<link rel="import" href="shared-styles.html"> 
<link rel="import" href="../bower_components/vaadin-grid/vaadin-grid.html"> 
<link rel="import" href="../bower_components/vaadin-date-picker/vaadin-date-picker.html"> 
<link rel="import" href="../bower_components/paper-input/paper-input.html"> 
<link rel="import" href="../bower_components/paper-button/paper-button.html"> 
<link rel="import" href="../bower_components/app-storage/app-localstorage/app-localstorage-document.html"> 






<dom-module id="my-view1"> 
    <template> 
    <style include="shared-styles"> 
     :host { 
     display: block; 

     padding: 10px; 
     } 
     .form { 
     display: flex; 
     flex-direction: column; 
     } 
     .form paper-input { 
     flex: 1; 
     margin-right: 10px; 
     } 
     .form vaadin-date-picker { 
     flex: 1; 
     margin-top: 10px; 

     } 
     .form paper-button { 
     margin-top: 10px; 
     align-self: flex-end; 
     } 

    </style> 
    <div class="card"> 
     <div class="form"> 
     <paper-input label="Sum" value="{{todo.task}}" auto-validate placeholder="Suma" required=true pattern="[0-9]*" error-message="Numbers only"></paper-input> 
     <vaadin-date-picker label="When" value="{{todo.due}}"></vaadin-date-picker> 
     <paper-button raised on-tap="_addToDo">Add</paper-button> 
     </div> 
<br> 
     <vaadin-grid items={{todos}}> 

     <vaadin-grid-column width="calc(50% - 100px)"> 
      <template class="header">Sum</template> 
      <template>{{item.task}}</template> 
     </vaadin-grid-column> 

    <vaadin-grid-column width="calc(50% - 100px)"> 
     <template class="header">When</template> 
     <template>{{item.due}}</template> 
    </vaadin-grid-column> 

    <vaadin-grid-column> 
     <template> 
      <div style="display: flex; justify-content: flex-end;"> 
      <button on-tap="_remove">Remove</button> 
      </div> 
     </template> 
     </vaadin-grid-column> 

    </vaadin-grid> 
    </div> 
<app-localstorage-document key="todos" data="{{todos}}"> 
</app-localstorage-document> 
    </template> 



    <script> 
    class MyView1 extends Polymer.Element { 
     static get is() { return 'my-view1'; } 

     static get properties() { 
     return { 
      todo: { 
      type: Object, 
      value:() => { return {} } 
      }, 
      todos: { 
      type: Array, 
      value:() => [] 
      } 
     }; 
     } 

     _addToDo() { 
     this.push('todos', this.todo); 
     this.todo = {}; 
     }; 

     _remove() { 
     console.log("Clicked!"); 
     }; 


    } 


    window.customElements.define(MyView1.is, MyView1); 

    </script> 
</dom-module> 

所以_addToDo按鈕工作,但不是_remove按鈕。當我打開控制檯時,這是空的。

請讓我知道我在這裏做錯了什麼。謝謝!

回答

1

由於button是原生HTML元素on-tap將不起作用。

將其更改爲像paper-button這樣的聚合物元素或將on-tap更改爲onclick

+0

非常感謝!這工作!現在您對如何編輯_remove函數有所瞭解,以便從應用程序存儲中刪除條目? – unkn0wnx