0
爲了得到我使用的輸入的變化以下從模板DOM重複
<template is="dom-repeat" items="{{employees}}">
<div>First name: <input on-change="cambiado" value="{{item.first::change}}"></div>
<div>Last name: <input on-change="cambiado" value="{{item.last::change}}"></div>
</template>
...
<script>
...
cambiado(e){
var datos=this.employees[e.model.__data.index]
setTimeout(function() {
console.log(datos.first+' '+datos.last)
}, 1000);
}
...
</script>
聚合物得到改變,但我相信,聚合物可以在easer方式獲取事件或剛剛得到的輸入改變。謝謝。
這與觀察員完整的元素不起作用:
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id='employee-list'>
<template>
<div>Employee List</div>
<p></p>
<template is="dom-repeat" items="{{employees}}">
<div>First name: <input value="{{item.first}}"></div>
<div>Last name: <input value="{{item.last}}"></div>
</template>
</template>
<script>
class EmployeeList extends Polymer.Element {
static get is() { return 'employee-list' }
static get properties() {
return {
item: {
type: Object,
value: function() {
return {};
}
}
}
}
static get observers() {
return [
'itemChanged(item.*)'
]
}
constructor() {
super()
this.employees = [
{ first: 'Bob', last: 'Li' },
{ first: 'Ayesha', last: 'Johnson' },
{ first: 'Fatma', last: 'Kumari' },
{ first: 'Tony', last: 'Morelli' }
];
}
itemChanged(first) {
if (first) {
console.log('new first: ' + first);
} else {
console.log('first is undefined');
}
}
}
customElements.define(EmployeeList.is, EmployeeList)
</script>
</dom-module>
觀察到的函數只是在加載元素時觸發,而不是在輸入新值時觸發。可能我想念一些東西。 – Mbanolas
選中此項,可能有所幫助:http://plnkr.co/edit/dkFohUbkTZbZiKBlU0to?p=preview –