我感谢您对此提供的任何帮助。所以这就是事情:我试图将数组传递给我用聚合物创建的自定义元素。事实是,它不起作用,当我打印该数组时,它给出了null。这是代码:
<link rel="import" href="../../../star-rating/star-rating.html">
<dom-module id="show-rating-answer">
<style>
</style>
<template>
<div id="scrollable" class="scrollable">
<label class="control-label">[[answer]]</label>
<star-rating labels='[[data]]' readonly="[[readonly]]"></star-rating>
</div>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'show-rating-answer',
properties: {
answer:String,
index:Number,
data: {
type: Array,
value: []
},
readonly: {
type: Boolean,
value: false
}
},
ready:function(){
alert(this.data)
}
})
})();
</script>
show-rating-answer组件具有数组属性。我想将数组传递给Play模板中的标记:
@(currentSurvey:Survey) @ currentSurvey.questions.map {question =&gt; ...
@if(question.answers != None){
@if(question.questionType.get == "rating"){
@question.answers.map{answer =>
<show-rating-answer answer="@answer.answer" index="@answer.index" data="['@question.ratingLabels.get.label']" readonly="true"></show-rating-answer>
<show-rating-answer answer="@answer.answer" index="@answer.index" data="[@question.ratingLabels.get.label1,@question.ratingLabels.get.label2,@question.ratingLabels.get.label3,@question.ratingLabels.get.label4,@question.ratingLabels.get.label5]" readonly="true"></show-rating-answer>
}
}else{
@if(question.questionType.get == "multi"){
@question.answers.map{answer =>
<input type="checkbox" name="multiple" value="@answer.index"> @answer.answer<br>
}
}else{
@if(question.questionType.get == "single"){
@question.answers.map{answer =>
<input type="radio" name="single" value="@answer.index"> @answer.answer<br>
}
}
}
}
}
}
但它让我无效。我尝试过其他的事情:
<show-rating-answer answer="@answer.answer" index="@answer.index" data="['@question.ratingLabels.get.label1','@question.ratingLabels.get.label2','@question.ratingLabels.get.label3','@question.ratingLabels.get.label4','@question.ratingLabels.get.label5']" readonly="true"></show-rating-answer>
有人尝试过成功吗?
答案 0 :(得分:0)
好的我使用过的解决方案,问题是我使用'而不是'。 这个解决方案不起作用:
<show-rating-answer answer="@answer.answer" index="@answer.index" data="['@question.ratingLabels.get.label1','@question.ratingLabels.get.label2','@question.ratingLabels.get.label3','@question.ratingLabels.get.label4','@question.ratingLabels.get.label5']" readonly="true"></show-rating-answer>
因为元素被包裹在'。但如果我们像这样改变'for':
<show-rating-answer answer="@answer.answer" index="@answer.index" data='["@question.ratingLabels.get.label1","@question.ratingLabels.get.label2","@question.ratingLabels.get.label3","@question.ratingLabels.get.label4","@question.ratingLabels.get.label5"]' readonly="true"></show-rating-answer>
它有效!聚合物在某些细节上有点敏感。