세 개의 중첩 된 폴리머 요소가 있습니다. 각각에는 기본값이 있으며 게시 된 값으로 대체 될 수 있습니다.중첩 요소가있는 폴리머 이벤트 및 데이터 바인딩 이해?
하지만 그럴 수 없습니다.
켜기 create
이벤트가 존재하지 않습니다. 게시 된 값. ready
이벤트 자식 요소는 이미 ready
이며 업데이트되지 않았습니다. 현실에서
, 별도의 파일에있는 각 요소입니다. 예입니다.
Object.assign - es6 개체를 병합하는 방법입니다 (es6-shim 사용). 내가 원하는대로 사용하는 많은 중첩 된 요소를 통해서만 하나의 객체 경우
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/es6-shim/0.18.0/es6-shim.js"></script>
<script src="http://www.polymer-project.org/components/platform/platform.js"></script>
<link href="http://www.polymer-project.org/components/polymer/polymer.html" rel="import">
</head>
<body unresolved>
<polymer-element name="my-field" attributes="ask">
<template>
<span><content></content> Message: {{message}}</span>
</template>
<script>
(function() {
Polymer('my-field', {
defaultAsk: { message: "Hello from Field!" },
created: function() {
console.log('created-field', this.ask, this.message);
Object.assign(this, this.defaultAsk);
},
ready: function() {
console.log('ready-field', this.ask, this.message);
Object.assign(this, this.ask);
}
});
})();
</script>
</polymer-element>
<polymer-element name="my-shelf" attributes="ask">
<template>
<my-field ask="{{field}}"><content></content></my-field>
</template>
<script>
(function() {
Polymer('my-shelf', {
defaultAsk: { field: { message: "Hello from Shelf!" } },
created: function() {
console.log('created-shelf', this.ask, this.field);
Object.assign(this, this.defaultAsk);
},
ready: function() {
console.log('ready-shelf', this.ask, this.field);
Object.assign(this, this.ask);
}
});
})();
</script>
</polymer-element>
<polymer-element name="my-cabinet">
<template>
<my-shelf ask="{{shelf}}"><content></content></my-shelf>
</template>
<script>
(function() {
Polymer('my-cabinet', {
ask: { shelf: { field: { message: "Hello from outside!" } } },
defaultAsk: { shelf: { field: { message: "Hello from Cabinet!" } } },
created: function() {
console.log('created-cabinet', this.ask, this.shelf);
Object.assign(this, this.defaultAsk);
},
ready: function() {
console.log('ready-cabinet', this.ask, this.shelf);
Object.assign(this, this.ask);
}
});
})();
</script>
</polymer-element>
<my-cabinet>Yo!</my-cabinet>
</body>
</html>