[英]Polymer app not passing route parameters to component.
I am trying to access the url parameters in a polymer application using pagejs and I am unable to find out why the value remains unaccessible inside the components. 我正在尝试使用pagejs访问聚合物应用程序中的url参数,但无法找出为什么该值在组件内部仍然不可访问。
Here is what I had done on the routing.html file 这是我对routing.html文件所做的操作
page('/crews/edit/:crewId', function(data) {
app.params = data.params;
app.route = 'crew-edit';
setFocus(app.route);
});
which I then tried to pass into the page component 然后我尝试传递给页面组件
<section data-route="crew-edit" tabindex="-1">
<bw-crew-edit crewId="{{ app.params.crewId }}"></bw-crew-edit>
</section>
and then finally into the component itself 然后最后进入组件本身
<dom-module is="bw-crew-edit">
<template>
{{crewId}}
</template>
<script>
(function() {
"use strict";
Polymer({
is: 'bw-crew-edit',
properties: {
crewId: {
type: String,
notify: true,
observers: '_crewIdChanged'
}
},
_crewIdChanged: function() {
console.log(this.crewId);
},
});
})();
</script>
</dom-module>
I am sure that I have followed the order of things and am unable to figure out why the component isn't receiving the data. 我确信我已经按照事情的顺序进行了操作,并且无法弄清组件为什么不接收数据。
As indicated in Polymer docs : 如Polymer docs中所示 :
Property name to attribute name mapping
属性名称到属性名称的映射
...
...
When mapping attribute names to property names:
将属性名称映射到属性名称时:
Attribute names are converted to lowercase property names.
属性名称将转换为小写的属性名称。 For example, the attribute
firstName
maps tofirstname
.例如,属性
firstName
映射到firstname
。Attribute names with dashes are converted to camelCase property names by capitalizing the character following each dash, then removing the dashes.
通过在每个破折号后面使用大写字母,然后删除破折号,将带有破折号的属性名称转换为camelCase属性名称。 For example, the attribute
first-name
maps tofirstName
.例如,属性
first-name
映射到firstName
。
In your case, you would use the crew-id
attribute to set the crewId
property of your element: 在您的情况下,您可以使用
crew-id
属性设置元素的crewId
属性:
<bw-crew-edit crew-id="foo">
<head> <base href="https://polygit.org/polymer+1.4.0/components/"> <script src="webcomponentsjs/webcomponents-lite.min.js"></script> <link rel="import" href="polymer/polymer.html"> </head> <body> <bw-crew-edit crew-id="foo"></bw-crew-edit> <dom-module id="bw-crew-edit"> <template> <span>crewId: {{crewId}}</span> </template> <script> HTMLImports.whenReady(function() { Polymer({ is: 'bw-crew-edit', properties : { crewId: String }, ready: function() { console.log('crewId', this.crewId); } }); }); </script> </dom-module> </body>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.