Observe changes for an object in Polymer JS

前端 未结 3 1997
悲&欢浪女
悲&欢浪女 2021-01-05 15:52

I have an element with a model object that I want to observe like so:

         


        
3条回答
  •  生来不讨喜
    2021-01-05 16:15

    what I do in this situation is use the * char to observe any property change in my array, here an example of my JSON object:

    {
        "config": { 
            "myProperty":"configuraiont1",
            "options": [{"image": "" }, { "image": ""}]
         }
    };
    

    I create a method _myFunctionChanged and I pass as parameter config.options.* then every property inside the array options is observed inside the function _myFunctionChanged

    Polymer({ 
     observers: ['_myFunctionChanged(config.options.*)'] 
    });
    

    You can use the same pattern with a object, instead to use an array like config.options. you can just observe config.

提交回复
热议问题