0
작은 프로젝트의 Polymer 프레임 워크를 사용하려고 시도합니다. 다음은 객체객체 내부의 배열을 구문 분석하는 중 DOM 반복 오류가 발생했습니다.
내부의 배열을 분석 폴리머 DOM 반복 오류가 나는 오류가 발생하고이 설정으로 내 포트 설정 선언
<template>
<paper-material elevation="-1">
<template is="dom-repeat" items="{{roomConfig.ports}}">
<div class="container">
<div class="flexchild">{{item.portName}}</div>
<div class="flex1child">
<paper-toggle-button toggles checked$="{{item.portStatus}}"></paper-toggle-button>
</div>
<div class="flex1child"><iron-icon icon="icons:settings"></iron-icon></div>
</div>
</template>
</paper-material>
</template>
<script>
Polymer({
is: "port-config",
properties: {
roomConfig: {
type: Object,
value: function() {
return {};
}
}
}
});
</script>
코드 호출
<paper-tabs scrollable selected={{selected}}>
<template is="dom-repeat" items="{{rooms}}">
<paper-tab>{{item.name}}</paper-tab>
</template>
</paper-tabs>
<iron-pages selected="{{selected}}">
<template is="dom-repeat" items="{{rooms}}">
<div> <port-config room-config="{{item}}"></port-config> </div>
</template>
</iron-pages>
</template>
<script>
Polymer({
is: "rooms-config",
properties: {
selected: {
type:Number,
value: 0,
},
rooms: {
type: Array,
value: function() {
var testData = [
{
name: "Room1",
maxPorts: 16,
ports:{
type: Array,
value: function() {
var testData = [
{portName: "Port 1",portStatus: "true"},
{portName: "Port 2",portStatus: "true"},
{portName: "Port 3",portStatus: "true"},
{portName: "Port 4",portStatus: "true"},
];
return testData;
}
}
}
}
}
});
다음이다 [dom-repeat :: dom-repeat] : items
의 예상 배열 Object {}
감사합니다. Ton Mario. 나는 [link] (https://www.polymer-project.org/1.0/docs/devguide/properties)를 따라 갔고 다음과 같이 선언했다. 놀랐어. 속성 : { 사용자 : { 유형 : 배열, 값 : function() { return []; } } – rcreddy
이제 작동 했습니까? 나는 이런 식으로 값을 사용하는 폴리머 문서에 예가 있다는 것을 결코 알지 못했다. 이상하게 생긴다. 음, 아마도 함수로 값을 선언 할 수는 없지만, 이런 식으로 선언하는 사람은 본 적이 없습니다 ... 그렇다면 모든 것이 여러분이 놓친 하나의 괄호에 불과할 수 있습니다. – MarioAleo
값으로 함수를 사용하는 것은'Object'와'Array'에서만 사용됩니다. 자세한 내용은이 [link] (http://stackoverflow.com/questions/38811194/why-use-function-wrap-for-polymer-property-value-of-type-object)에서 확인할 수 있습니다. – a1626