聚合物中的两个聚合物的火基收集元素如何嵌入到dom-repeat? [英] How do you nest two of Polymer's firebase-collection elements inside dom-repeat?
问题描述
使用我的数据库结构,我首先必须检查用户可以访问哪些事件,然后从事件中获取该事件的信息。
此问题代码是,当我循环第二个firebase-collection时,事件上的数据绑定将一律重复,因此它将在每个h4上都是相同的名称。
$ b $那么在data ={{}}中有一个唯一变量的方法。
还是有更好的写出数据的方法?
< firebase-collection data ={ userData}}location ={{_ getCorrectUrl()}}>< / firebase-collection>
< template is =dom-repeatitems ={{userData}}as =user>
< firebase-collection data ={{events}}location ={{_ getCorrectEventsUrl(user .__ firebaseKey__)}}>< / firebase-collection>
< template is =dom-repeatitems ={{events}}as =event>
< h4> {{event.value.name}}< / h4>
< / template>
< / template>
我有一个解决方案,我认为不是最好的方法解决这个问题,但它对我有用。我创建了另一个名为我的用户的元素,我暴露了一个名为user的属性,该属性从第一个dom-repeat分配给用户的值。一切都行之有效,但我对此解决方案不满意。我仍然在寻找一个不涉及创建专用元素的解决方案。
< firebase-collection data = {{userData}}location ={{_ getCorrectUrl()}}>
< / firebase-collection>
< template is =dom-repeatitems ={{userData}}as =user>
< my-user user =[[user]]>< / my-user>
< / template>
另一个我的用户:
< dom-module id =my-user>
< template>
< firebase-collection data ={{events}}location ={{_ getCorrectEventsUrl(user)}}>< / firebase-collection>
< template is =dom-repeatitems ={{events}}as =event>
< h4> {{event.value.name}}< / h4>
< / template>
< / template>
< script>
(function(){
Polymer({
is:'my-user',
_getCorrectEventsUrl:function(obj){
return'https:// app .firebaseio.com / users /'+ obj .__ firebaseKey__;
},
属性:{
用户:{
类型:对象,
},
},
});
})();
< / script>
< / dom-module>
编辑
现在在回答这个问题的某个时候,我意识到当有人面对NoSQL数据库的这种情况时,它通常会突出显示设计中的一个问题。数据应该被去规范化,并且应该避免加入,就像SQL数据库中通常所做的那样。观看 SQL开发人员的Firebase数据库在YouTube上
I have a problem of looping two of Polymers firebase-collection elements. With my database structure i first have to check which events the user has access to, then get the information on that event from events.
The problem with this code is that when i loop the second firebase-collection the data-binding on "events" will be the same on all that repeats and therefore it will be the same name on every h4.
So is there a way of having a unique variable in data="{{ }}". or is there a better way of writing out the data?
<firebase-collection data="{{userData}}" location="{{_getCorrectUrl()}}"></firebase-collection>
<template is="dom-repeat" items="{{userData}}" as="user">
<firebase-collection data="{{events}}" location="{{_getCorrectEventsUrl(user.__firebaseKey__)}}" ></firebase-collection>
<template is="dom-repeat" items="{{events}}" as="event">
<h4>{{event.value.name}}</h4>
</template>
</template>
I have a solution which I consider not the best way to solve this issue, but it works for me. I created another element called 'my-user, I exposed an attribute called user which is assigned the value of user from the first dom-repeat. Everything works, however, I am not satisfied with this solution. I am still looking for a solution which doesn't involve creating a dedicated element for that.
<firebase-collection data="{{userData}}" location="{{_getCorrectUrl()}}">
</firebase-collection>
<template is="dom-repeat" items="{{userData}}" as="user">
<my-user user="[[user]]"></my-user>
</template>
and the other 'my-user':
<dom-module id="my-user">
<template>
<firebase-collection data="{{events}}" location="{{_getCorrectEventsUrl(user)}}" ></firebase-collection>
<template is="dom-repeat" items="{{events}}" as="event">
<h4>{{event.value.name}}</h4>
</template>
</template>
<script>
(function () {
Polymer({
is: 'my-user',
_getCorrectEventsUrl: function(obj) {
return 'https://app.firebaseio.com/users/' + obj.__firebaseKey__;
},
properties: {
user:{
type:Object,
},
},
});
})();
</script>
</dom-module>
EDIT
Now after sometime of answering this question I came to realize that when someone face such a situation with NoSQL database, it usually highlights a problem in the design. Data should be de-normalized and one should avoid joining like what is normally done in SQL databases. Watch the The Firebase Database For SQL Developers on youtube.
这篇关于聚合物中的两个聚合物的火基收集元素如何嵌入到dom-repeat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!