【发布时间】:2016-11-11 02:40:23
【问题描述】:
我有一个关于我的代码行为方式的问题列表,关于观察者
问题
1 - 为什么当我刷新页面时观察者会发出警报?
2 - 为什么我在刷新页面时会收到两次警报?
3 - 为什么警报中的值会有所不同,
a - 第一个警报 - [1,2,3,4,5]
b - 秒警报 - 1,2,3,4,5
4 - 除非手动更改某些内容,否则我不会调用观察者,我不希望在页面刷新时调用它
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>
【问题讨论】:
标签: polymer polymer-1.0