Polymer 如何使用deepstream记录选择ds列表
我在聚合物应用程序中选择ds列表时遇到问题。我有一个功能性的聊天标题列表(实现为deepstream记录),应该用来选择匹配的聊天历史记录(实现为包含聊天消息作为记录的deepstream列表) 现在,我如何不仅设置聊天名称本身的记录,而且设置包含聊天历史记录的ds列表?和:ds列表的哪些属性可用作选择它的属性(例如id?名称?)Polymer 如何使用deepstream记录选择ds列表,polymer,deepstream.io,Polymer,Deepstream.io,我在聚合物应用程序中选择ds列表时遇到问题。我有一个功能性的聊天标题列表(实现为deepstream记录),应该用来选择匹配的聊天历史记录(实现为包含聊天消息作为记录的deepstream列表) 现在,我如何不仅设置聊天名称本身的记录,而且设置包含聊天历史记录的ds列表?和:ds列表的哪些属性可用作选择它的属性(例如id?名称?) 很抱歉问了这么长的问题,非常感谢您的回答 首先,请原谅,你所举的例子把我弄糊涂了。 第二个代码段似乎是todo应用程序的示例代码。如果您使用描述性变量名,这将非常有帮
很抱歉问了这么长的问题,非常感谢您的回答 首先,请原谅,你所举的例子把我弄糊涂了。 第二个代码段似乎是todo应用程序的示例代码。如果您使用描述性变量名,这将非常有帮助 您似乎拥有允许用户创建新聊天名称的代码,其中创建的记录名为
'polymer-example/$RANDOM\u ID'
(我建议使用类似'chat-details/$RANDOM\u ID'
)的值为{name:$chat\u name,选中:false
。
然后将记录“polymer-example/$RANDOM_ID”
添加到具有某些polymer属性的列表中
您有一个deepstream名称列表,其中每个名称对应于包含聊天名称的deepstream记录
假设您希望存储对当前选定聊天的引用,我建议您将相应的聊天id(在提供的示例中称为recordId
)存储为属性,或者存储对记录本身的引用
为了存储聊天历史记录,我建议为每个聊天记录创建另一个列表(称为“chat-history/$chat\u ID”)。
然后,对于每条新消息,您可以创建相应的记录('chat-message/$RANDOM_ID'
),并使用该记录存储消息内容、发件人姓名、时间等。现在将消息记录的名称添加到聊天历史记录列表中
选择正确的聊天历史记录只是获取当前选择的聊天(
chatId
),获取包含消息ID列表的列表'chat-history/'+chatId
,然后获取记录'chat-message/'+messageId
非常感谢您的详细回答!关于变量名,您是完全正确的,它们仍然是我使用deepstream todo示例进行实验的遗迹。再次感谢大家!
<div class="chatlist">
<!-- This is the list of chats -->
<paper-menu selected="[[chatlist]]">
<paper-item>
<paper-input label="New Chat:" id="chatName" on-keydown="setChatName"></paper-input>
</paper-item>
<template
is="dom-repeat"
items="[[todos]]"
as="recordId">
<div role="listbox">
<chat-names
name="[[recordId]]">
</chat-names>
</div>
</template>
</paper-menu>
</div>
<!-- this is the chat history -->
<iron-pages
selected="[[chatlist]]"
attr-for-selected="chatView"
fallback-selection="chatView404"
role="main">
<template
is="dom-repeat"
items="[[todos]]"
as="recordId">
<chat-view
chatView="[[???]]"
name="[[recordId]]">
</chat-view>
</template>
</iron-pages>
setChatName: function (e) {
if (e.which === 13) {
var recordId = 'polymer-example/' + this.ds.getUid();
var todo = this.$$( '.new-record-input' ).value;
var todoRecord = this.ds.record.getRecord( recordId );
var todoList = this.ds.record.getList( this.name );
todoRecord.set( { name: todo, checked: false } )
todoRecord.whenReady( function() {
todoList.addEntry( recordId );
} );
this.$.chatName.value = '';
}
},