【发布时间】:2017-01-09 18:20:31
【问题描述】:
我有一个带有模型对象的元素,我想像这样观察:
<polymer-element name="note-editor" attributes="noteTitle noteText noteSlug">
<template>
<input type="text" value="{{ model.title }}">
<textarea value="{{ model.text }}"></textarea>
<note-ajax-button url="/api/notes/" method="POST" model="{{model}}">Create</note-ajax-button>
</template>
<script>
Polymer('note-editor', {
attached: function() {
this.model = {
title: this.noteTitle,
text: this.noteText,
slug: this.noteSlug
}
},
});
</script>
</polymer-element>
我想观察模型的变化,但显然不可能在元素中使用 modelChanged 回调,也不能在 note-ajax-button 元素中使用。怎么了?我该怎么做?
我试过单独观察这些字段,但它一点也不干净。您在那里看到的按钮元素的状态应该根据模型状态而改变,所以我需要观察对象的变化,而不是属性的变化。 谢谢!
【问题讨论】:
标签: polymer