简体   繁体   English

Polymer应用程序未将路线参数传递给组件。

[英]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 to firstname . 例如,属性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 to firstName . 例如,属性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> 

codepen 码笔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 查询 - 参数 <app-route> 聚合物元素 - query-params in <app-route> element of polymer Polymer应用程序路线:到同一页面的多个路线? - Polymer app-route: multiple routes to same page? 聚合物/纤维网组件 <app-router> 不能获取/ <route> - Polymer/web components <app-router> Cannot GET/<route> 将路由文件中的指定参数传递给laravel中的控制器 - Passing specified parameters in route file to the controller in laravel 使用RESTful控制器时将路由参数传递给过滤器 - Passing Route Parameters to Filters when Using RESTful Controllers 聚合物1.6-应用在刷新后显示空白页。 我在用 <app-route> 路由器 - Polymer 1.6 - App shows blank page after refresh. I am using <app-route> router 使用javascript中的参数进行聚合物路由 - polymer routing with parameters from javascript 如何从子组件中访问映射到父组件的路由参数? (角度 2.0) - How do I access route parameters that are mapped to a parent component from within a child component? (angular 2.0) 如何将指向 angular 8 应用程序的 index.html 路由转换为包含原始参数的 angular 路由? - How to convert an index.html route directed to an angular 8 app into angular route that contains the original parameters? 向其他用户传递带有查询参数的 Angular 应用 URL - Passing angular app URL with query parameters with other users
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM