[英]polymer - How to pass data to an element view
So this might be a difficult question to understand, but essentially I am trying to pass a value to another view of my polymer app. 因此,这可能是一个很难理解的问题,但从本质上讲,我试图将一个值传递给我的聚合物应用程序的另一个视图。
secrets-app.html 秘密-app.html
<a on-tap="_loadHuddle" name="{{item.$key}}" href="#/view2" >[[item.$key]]</a>
<iron-pages
id="pages"
selected="[[page]]"
attr-for-selected="name"
fallback-selection="view404"
role="main">
<my-view1 name="view1" route="{{route}}"></my-view1>
<my-view2 name="view2" route="{{route}}" secret="{{secret}}"></my-view2>
<my-view404 name="view404"></my-view404>
</iron-pages>
<script>
properties: {
secret: {
type: String,
value: ''
}
},
_loadHuddle: function(e) {
var clickedElement = e.target;
// magically get data from the list menu item clicked!
var item = this.$.messages.itemForElement(e.target);
console.log("item", item)
this.set('secret', item["which"]);
console.log("loading huddle");
this.set('route.path', '/view2');
// this.$.pages.select("view2");
this.$.drawer.close();
},
</script>
When I click the a
tag I want to be able to store the "secret" and send it to view2. 当我单击
a
标签时,我希望能够存储“秘密”并将其发送到view2。 My understanding is that I should be able to access this through this.secret
but this is not the case. 我的理解是,我应该能够通过
this.secret
访问它,但事实并非如此。
I have a _secrets
observer in my-view2.html that gets called when this.secrets
is set but then something with the route.path
makes this.secret = undefined
. 我有一个
_secrets
我-view2.html观测时调用this.secrets
设置但随后事情与route.path
使得this.secret = undefined
。 I need this defined so I can eventually make the right query to firebase. 我需要此定义,以便最终可以对firebase进行正确的查询。
This is like my first week with polymer so still learning, any help would be appreciated :) 这就像我与聚合物的第一周一样,所以仍然在学习,任何帮助将不胜感激:)
I bet that it's because you're using a tag. 我敢打赌,这是因为您正在使用标签。 Try changing it to another tag, like , and it will start to work.
尝试将其更改为另一个标签,例如,它将开始起作用。
Other than that, you can save variables in localStorage or even in the window object. 除此之外,您可以将变量保存在localStorage甚至窗口对象中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.