我有我的代码是行为方式的问题列表,以及关于观察员观察者在聚合物中的怪异行为?
质询
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