如何在 Polymer 1.0 中将值从一个自定义元素传播到另一个?

How to propagate value from one custom element to another in Polymer 1.0?

我有两个自定义元素。学生-details.html 和学生-service.html

学生-details.html长这样

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="student-service.html">
<dom-module id="student-details">
<style>
</style>
<template>
 <h1>Student Details</h1>
<h1>{{studentId}}<h1> //This value is printed properly
 <student-service   user-data={{studentId}} service-name="StudentDetails"  response-data={{responseData}} ></student-service>



     <h1>{{responseData.name}}</h1>
     <img width="70" height="70" src="{{responseData.image}}" />
     <h1>{{responseData.qualification}}</h1>

     <h1>{{responseData.speciality}}</h1>
     <h1>{{responseData.phone}}</h1>

     <h1>{{responseData.email}}</h1>

     <template is="dom-repeat" items="{{responseData.addresses}}">
     <h1>{{item.street}}</h1>
     <h1>{{item.area}}</h1>
     </template>

</template>
<script>
Polymer({
is:'student-details',
properties:{
 studentId: String,
 notify: true
}

});

</script>
</dom-module>

student-service 将输入作为 studentId 并 returns 在 responseData 中进行响应。

如果我使用它显示的 {{studentId}} 访问 student-details.html 本身中的值 studentId,但我无法将相同的值发送到 student-service 元素中的用户数据输入.

注意:如果我对 studentId 进行硬编码,效果会很好。 我认为我没有遵循正确的传递价值的方式。请推荐

放心使用熨斗-ajax

https://elements.polymer-project.org/elements/iron-ajax

希望能帮到你

您错过了 {{studentId}}

周围的引号

尝试:

<student-service user-data="{{studentId}}" service-name="StudentDetails"  response-data="{{responseData}}"></student-service>

您可以尝试使用类似于 <student-service user-data$="{{studentId}}"

代码看起来没有错。很可能是在设置 studentId 之前调用了学生服务。

尝试查看您的代码流程并确保仅在设置 studentId 后调用该服务。