Template render data from remote connection


#1

Hello All!

I’m trying to tonnect from mobile app to remote web app. I use DDP.connect() to connect to remote web app. But I don’t see data in my template.

Here my mobile app code:
main.js

  Meteor.remoteConnection = DDP.connect('http://remoteserver.com:3000'); //remote server
  Items= new Mongo.Collection('items', { connection: Meteor.remoteConnection }); //existed collection on remote server
  if (Meteor.isServer) {
    Meteor.remoteConnection.subscribe('items');
  }
  
  if (Meteor.isClient) {
      Meteor.remoteConnection.subscribe('items', function() {
          var items = Items.find();
           console.log(items.count()); // return 3
      });
   }
  
  Router.route('/', function() {
      this.render('home');
   });

Here is my template:

<template name="home">
    <!-- Status bar overlay for full screen mode (PhoneGap) -->
    <div class="statusbar-overlay"></div>
    <!-- Views -->
    <div class="views">
        <!-- Your main view, should have "view-main" class -->
        <div class="view view-main">
            <!-- Top Navbar-->
            <div class="navbar">
                <div class="navbar-inner">
                    <!-- We need cool sliding animation on title element, so we have additional "sliding" class -->
                    <div class="center sliding">SMART Workout</div>
                </div>
            </div>
            <!-- Pages container, because we use fixed-through navbar and toolbar, it has additional appropriate classes-->
            <div class="pages navbar-through toolbar-through">
                <!-- Page, "data-page" contains page name -->
                <div data-page="index" class="page">
                    <!-- Scrollable page content -->
                    <div class="page-content">
                        {{#if connStatus}}
                        <em>{{connStatus}}</em>
                        {{/if}}
                    </div>
                    <div>
                        {{#each items}}
                        <h3>{{itemName}}</h3>
                        {{/each}}
                    </div>
                </div>
            </div>
            <!-- Bottom Toolbar-->
            <div class="toolbar">
                <div class="toolbar-inner">
                    <!-- Toolbar links -->
                    <a href="#" class="link">Link 1</a>
                    <a href="#" class="link">Link 2</a>
                </div>
            </div>
        </div>
    </div>
</template>

And helper:

Template.home.helpers({
     connStatus: function() {
         return Meteor.status().status;
     },
     items: function() {
         return Items.find();
     }
});

So, on the page I don’t see items.

How to subscribe to remote collection and render its data in template?