我有我的代碼是行爲方式的問題列表,以及關於觀察員觀察者在聚合物中的怪異行爲?
質詢
1 - 爲什麼觀察者警告,當我刷新頁面?
2 - 爲什麼我在刷新頁面時收到兩次警報?
3 - 爲什麼在警報而變化的值,
一 - 第一警報 - [1,2,3,4,5]
b - 塞康警報 - 1,2,3,4, 5
4 - 我不什麼觀察者正在如果沒有什麼改變manualy稱爲直到,我不希望它被稱爲在頁面上刷新
5 - 什麼是::input
辦?
自定義元素
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="icon-toggle-second-demo">
<template>
<style>
</style>
<br>
<input type="text" value="{{first::input}}" >
second element
<button>Reset</button>
{{first}}
{{asdf}}
</template>
<script>
Polymer({
is: "icon-toggle-second-demo",
properties: {
'first': {
type: Array,
reflectToAttribute: true,
value: "[1,2,3,4,5]"
},
'second': {
type: String,
notify: true,
readOnly: false,
value: "default"
}
},
observers:[
'changedEvent(first.*, 0)', 'con()'
],
changedEvent: function(changeRecord, index){
alert(changeRecord.base);
},
con: function(){
console.log("asdf");
}
});
</script>
</dom-module>
家長HTML
<!doctype html>
<html>
<head>
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="icon-toggle-second-demo.html">
<style is="custom-style">
</style>
</head>
<body>
demo/index.html - parent <br>
<icon-toggle-second-demo ></icon-toggle-second-demo>
<script>
</script>
</body>
</html>
FIRSTLY根據docs-Type:constructor(布爾值,日期,數字,字符串,數組或對象)之一鍵入屬性可以具有這些值。我正在使用reflectToAttribute只是爲了試驗。問題 - 當reflectToAttribute爲true時,警報會被觸發兩次,其他則會觸發一次。爲什麼? –
是的,你的類型值是有效的,但我指出的是你的類型和值屬性不同步。 'type'說它的數組和'value'說它的字符串 – a1626
我已經更新了我的問題2和3的答案 – a1626