I get "Can not read property 'apply' of undefined" by passing an array to "dom-repeat"

0

When a dom-repeat passes an array that is inside an object, I receive this error:

  "Cannot read property 'apply' of undefined"

This is the code:

<link rel="import" href="../bower_components/polymer/polymer.html">

<dom-module id="hola-mundo">
	<style>
		h1{
			color: blue;
		}
	</style>
	
	<template>
			
		<button on-tap="test">myButton</button>	    		

		<template is="dom-repeat" items="{{myObject.parameters}}">
				<div>{{item.name}}</div>				
		</template>
	</template>
</dom-module>

<script>
	Polymer({
		is: "hola-mundo",
		properties: {
			myObject: {
				type:Object,
				value: {
					parameters: {
						type: Array,
						value: []
					},
					color: {
						type: String,
						value: 'red'
					}	
				}
			}
				
		},
		
		test: function(){
			this.push('myObject.parameters', { 'id': '1', 'name': 'test'});
		},		
	});
</script>

If the array is outside the object it works fine, but I need it to be inside the object.

Can someone correct my code? I have not found the error.

Thank you very much!

    
asked by frontenddevelopper 06.06.2018 в 15:27
source

1 answer

0

The declaration of properties more than the first level is not supported I think. Try declaring myObject in the following way and it should work for you:

properties: {
    myObject: {
        type:Object,
        value: {
            parameters: [],
            color: 'red'
        }
    }
},
    
answered by 07.06.2018 / 09:49
source