close

package.json :

{
  "name": "week_1_starter_code",
  "version": "1.0.0",
  "description": "",
  "main": "textcircle.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel-runtime": "^6.18.0",
    "bcrypt": "^0.8.7"
  }
}
-----------------------------------------------------------------------------------------
textcircle.html :

<head>
        <title>textcircle</title>
</head>

<body>
        <h1>Welcome to TextCircle</h1>
        {{>editor}}
</body>

<template name="editor">
</template>
----------------------------------------------------------------------------------------------
textcircle.js :

this.Documents = new Mongo.Collection("documents");
if (Meteor.isClient){

}

if (Meteor.isServer){
        Meteor.startup(function(){
                // code to run on server at startup
                if (!Documents.findOne()){
                     Documents.insert({title:"my new document"});
                }
        });
}
 

-----------------------------------------------------------------------------------------

在  web console 輸入 Documents.findOne() 可看到 title 資訊

 

改一下 : 於 clinet 端的 console show log

先匯入 sharejs-codemirror

[chio@test textcircle]$   meteor add mizzao:sharejs-codemirror

textcircle.html :

<head>
        <title>textcircle</title>
</head>

<body>
        <h1>Welcome to TextCircle</h1>
        {{>editor}}
</body>

<template name="editor">
        {{>sharejsCM docid=docid id="editor"}}
</template>
[chio@test textcircle]$ vi textcircle.js
[chio@test textcircle]$ vi textcircle.js
[chio@test textcircle]$ more textcircle.html
<head>
        <title>textcircle</title>
</head>

<body>
        <h1>Welcome to TextCircle</h1>
        {{>editor}}
</body>

<template name="editor">
        {{>sharejsCM docid=docid id="editor"}}
</template>
-------------------------------------------------------------------------------
textcircle.js : (clinet 要等 server  端有資料才回應所以要判斷回應的值在不在)

this.Documents = new Mongo.Collection("documents");
if (Meteor.isClient){
        Template.editor.helpers({
                docid:function(){
                        console.log("doc id helper:");
                        console.log(Documents.findOne());
                        if (Documents.findOne()){
                                return Documents.findOne()._id;
                        }
                        else
                        {
                                return undefined;
                        }
                }
        });

}

if (Meteor.isServer){
        Meteor.startup(function(){
                // code to run on server at startup
                if (!Documents.findOne()){
                     Documents.insert({title:"my new document"});
                }
        });
}

 

arrow
arrow
    全站熱搜

    echochio 發表在 痞客邦 留言(0) 人氣()