我正在使用Ionic 2和meteor / MongoDB。
当我执行以下操作时,inserts
chat
localChatCollection
对象进入 let promise: Promise<Mongo.Collection<Chat>> = this.findChats();
promise.then((data: Mongo.Collection<Chat>) => {
let localChatCollection: Mongo.Collection<Chat> = new Mongo.Collection<Chat>(null);
data.find().forEach(function (chat: Chat) {
console.log('==> ' + chat);
localChatCollection.insert(chat);
});
:
localChatCollection
但是,如果我全局定义insert
,则chat
insert
对象不会private localChatCollection: Mongo.Collection<Chat> = new Mongo.Collection<Chat>(null);
....
this.localChatCollection.insert(chat);
。没有错误,但该过程在collection
行停止。
CustomView
我有什么想法可以将其插入到全局定义的<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentTop="true"/>
<View
android:id="@+id/view2"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<com.musicmuni.riyaz.views.CustomView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@id/view2"
android:layout_toEndOf="@id/view2"
android:layout_below="@id/view1"/>
</RelativeLayout>
?
答案 0 :(得分:0)
这样可行,但我认为这不是最优雅的解决方案:
let that = this;
data.find().forEach(function (chat: Chat) {
that.localChatCollection.insert(chat);
});