polymer 1 当行为中对象的 属性 被修改时,观察者不会被触发

polymer 1 the observer is not fired when the one property of an object in a behavior is modified

当 selectedWidget.id 值更改时,观察器未检测到更改。

这位观察者:

观察者:['functionOberveId(selectedWidget.id)'],

代码hola-mundo.html是:

<link rel="import" href="./bower_components/polymer/polymer.html">
<link rel="import" href="./hidding-behaviour.html">
<dom-module id="hola-mundo">
 <style>
  h1{
   color: blue;
  }
 </style>
 <template>
  <h1>hello world</h1>
  <button on-click="changeValuebahviourId">changeValuebahviourId</button>
  <button on-click="showValuebehaviourId">showValuebahviourId</button>
  
 </template>

 <script>
  Polymer({
   is: "hola-mundo",
   behaviors: [Hidding],
   observers: ['functionOberveId(selectedWidget.id)'],
   
   
   functionOberveId: function(){
    console.log("the observer is working fine")
    console.log("the id value in behaviour is: " + this.selectedWidget.id)
   },
   
   changeValuebahviourId: function(){
    this.selectedWidget.id= (this.selectedWidget.id +1)
   }, 
   showValuebehaviourId: function(){
    console.log("the id value in behaviour is: " + this.selectedWidget.id)
   }, 
  });
 </script>
</dom-module>

隐藏代码-behaviour.html是:

<script>
    Hidding = {        
        properties:{
            selectedWidget: {
                type: Object,
                value: {
                    item: null,
                    id: 0,
                },
            },
        },
        
    }
</script>

index.html代码是:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Prueba de index</title>
 <script src="./bower_components/webcomponentsjs/webcomponents.js"></script>
 <link rel="import" href="./hola-mundo.html">
</header>
<body>

 <hola-mundo></hola-mundo>
</body>
</html>

为什么当我们按下按钮时观察者没有被射击 "changeValuebahviourId"?

我很感激这方面的帮助我已经审查了很长时间,但我找不到解决方案。

非常感谢。

Polymer 需要知道发生了一些变化而不是调用

this.selectedWidget.id= (this.selectedWidget.id +1)

使用这个:

this.set('selectedWidget.id', this.selectedWidget.id +1);

Documentation polymer