天天看點

Using View and Data API with Meteor 本文轉自峻祁連. Moving to Cloud/Mobile部落格園部落格,原文連結:http://www.cnblogs.com/junqilian/p/5173884.html,如需轉載請自行聯系原作者

Using View and Data API with Meteor 本文轉自峻祁連. Moving to Cloud/Mobile部落格園部落格,原文連結:http://www.cnblogs.com/junqilian/p/5173884.html,如需轉載請自行聯系原作者

├── README.md 

├── client 

│   ├── index.html 

│   ├── index.js 

│   ├── style.css 

│   └── viewer 

│       ├── viewer.html 

│       └── viewer.js 

├── lib 

└── server 

    └── index.js

The “client” folder contains the contents which are running at client side, “server” folder contains the scripts which are running at server side.

===========================

# Meteor packages used by this project, one per line. 

# Check this file (and the other files in this directory) into your repository. 

# 'meteor add' and 'meteor remove' will edit this file for you, 

# but you can also edit it by hand.

meteor-base             # Packages every Meteor app needs to have 

mobile-experience       # Packages for a great mobile UX 

mongo                   # The database Meteor supports right now 

blaze-html-templates    # Compile .html files into Meteor Blaze views 

session                 # Client-side reactive dictionary for your app 

jquery                  # Helpful client-side library 

tracker                 # Meteor's client-side reactive programming library

standard-minifiers      # JS/CSS minifiers run for production mode 

es5-shim                # ECMAScript 5 compatibility for older browsers. 

ecmascript              # Enable ECMAScript2015+ syntax in app code

autopublish             # Publish all data to the clients (for prototyping) 

insecure                # Allow all DB writes from clients (for prototyping)

# Allow to send REST calls to authentication server 

http 

=============================

With that, I can add a Meteor method to do authentication from “/server/index.js”,. It can be called from client side with “Meteor.call()”. Here is the code snippet, please note that I am using synchronous mode when doing “Meteor.http.post”, as I found that I cannot get the returned access token from client side afterwards if I use async mode.

Now let’s back to the client side, in “/client/viewer/viewer.html” I created a simple template as below:

In the “\viewer\viewer.js”, I will try to get the access token first with following code:  

When the viewer template is created, I call to the server side meteor method to do authentication and get the access token, once I get the access token, I can initialize a viewer at client side with View and Data JavaScript API. Now I can see the token from console of developer tool, so far so good.

Using View and Data API with Meteor 本文轉自峻祁連. Moving to Cloud/Mobile部落格園部落格,原文連結:http://www.cnblogs.com/junqilian/p/5173884.html,如需轉載請自行聯系原作者

"Uncaught ReferenceError: AutodeskNamespace is not defined"

If I examined to the network tab of browser development tool, the “viewer3d.min.js” has not been loaded yet when I was trying to use it.

Meteor controls the load process of JS files and it is not easy to control the load order, here is the load order as described on meteor document:

The JavaScript and CSS files in an application are loaded according to these rules: Files in the lib directory at the root of your application are loaded first. Files that match main.* are loaded after everything else. Files in subdirectories are loaded before files in parent directories, so that files in the deepest subdirectory are loaded first (after lib), and files in the root directory are loaded last (other than main.*). Within a directory, files are loaded in alphabetical order by filename. These rules stack, so that within lib, for example, files are still loaded in alphabetical order; and if there are multiple files named main.js, the ones in subdirectories are loaded earlier.

So since viewer js lib is loaded very late, I cannot use it in viewer.js to initialize the viewer. Luckily, I found that if I put the <script src=””/> tag into <head>, it will be loaded first, so in “/client/index.html”:

OK, with that I can initialized viewer in “/client/viewer/viewer.js” file, the code snippet is below:

Now I have a running meteor application with viewer embedded. I also posted my sample on github, so you may want to take a look to check the complete code. Hope it helps some.

<a href="https://github.com/Developer-Autodesk/meteor-view.and.data.api">https://github.com/Developer-Autodesk/meteor-view.and.data.api</a>

郵箱:[email protected] 

轉載請保留此資訊。

繼續閱讀