2016-08-02 62 views
0

我正在爲流星創建一個Mongo數據庫。我創建了一個startup.js文件,所以流星可以加載文件。一旦流星開始它崩潰。任何人都可以幫我嗎?當startup.js加載使用Mongo時,流星崩潰

HTML文件

<body> 
    <div class="container"> 
    {{> images}} 
    </div> 
</body> 
<template name="images"> 
    <div class="row"> 
    {{#each images}} 
    <div class="col-xs-12 col-md-3"> 
     <div class="thumbnail"> 
     <img class="js-image" src="{{img_src}}" alt="{{img_alt}}" /> 
     </div> 
    </div> 
    {{/each}} 
    </div> 
</template> 

startup.js文件

if (Meteor.if(Meteor.isServer) { 
    Meteor.startup(function() { 
     if (Images.find().count() == 0) { 
      Images.insert({ 
       img_src: "laptops.jpg", 
       img_alt: "some laptops on a table" 
      } 
      }) 
     } 
    }); 
}) 

image_share.js

Images = new Mongo.Collection("images"); 
if (Meteor.isClient) { 
    var img_data = [{ 
    img_src: "laptops.jpg", 
    img_alt: "some laptops on a table" 
    }, { 
    img_src: "bass.jpg", 
    img_alt: "a bass player" 
    }, ]; 
    Template.images.helpers({ 
    images: img_data 
    }); 
    Template.images.events({ 
    'click .js-image': function(event) { 
     $(event.target).css("width", "50px"); 
    } 
    }); 
} 

錯誤日誌

W20160802-22:15:47.535(3)? (STDERR) (function(Npm,Assets){(function(){if (Meteor.if(Meteor.isServer){ 
W20160802-22:15:47.535(3)? (STDERR)                ^
W20160802-22:15:47.535(3)? (STDERR) SyntaxError: Unexpected token { 
W20160802-22:15:47.535(3)? (STDERR)  at /data/coursera/meteor.js/week_1/fotini_test/.meteor/local/build/programs/server/boot.js:278:30 
W20160802-22:15:47.535(3)? (STDERR)  at Array.forEach (native) 
W20160802-22:15:47.535(3)? (STDERR)  at Function._.each._.forEach (/home/fotini/.meteor/packages/meteor-tool/.1.3.2_4.s16sw2++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11) 
W20160802-22:15:47.535(3)? (STDERR)  at /data/coursera/meteor.js/week_1/fotini_test/.meteor/local/build/programs/server/boot.js:133:5 
=> Exited with code: 8 

`

回答

0
if (Meteor.if(Meteor.isServer)) { 
    Meteor.startup(function() { 
     if (Images.find().count() == 0) { 
      Images.insert({ 
       img_src: "laptops.jpg", 
       img_alt: "some laptops on a table" 
      }); 
     } 
    }); 
} 

你忘了一個關閉「)」和其他一些錯誤。