2013-01-12 4 views
1

Meteor 앱에서 작업 중이며 Backbone의 라우팅 기능과 함께 멀티 페이지 기능을 추가하려고합니다. 그러나, 나는이 수행 할 때Meteor 앱에서 백본이 정의되지 않았습니다.

meteor add backbone 
meteor add underscore 

다음은이 메시지와 함께 충돌 응용 프로그램 내에서 간단한 '안녕하세요 세계'를 만들려고 :

ReferenceError: Backbone is not defined 
at app/backbone.js:33:2 
at run (/Users/timj/Documents/backbone/.meteor/local/build/server/server.js:142:63) 
at Array.forEach (native) 
at Function._.each._.forEach (/usr/local/meteor/lib/node_modules/underscore/underscore.js:79:11) 
at run (/Users/timothyjaeger/Documents/backbone/.meteor/local/build/server/server.js:142:7) 
Exited with code: 1 

확실하지 무엇을 내가 때문에 잘못하고 있어요 내 유성 애플 리케이션에 이미 백본을 추가했습니다! JS는 다음과 같습니다

if (Meteor.isClient) { 

     var AppView = Backbone.View.extend({ 
     // el - stands for element. Every view has a element associate in with HTML content will be rendered. 
     el: '#container', 
     // It's the first function called when this view it's instantiated. 
     initialize: function(){ 
     this.render(); 
     }, 
     // $el - it's a cached jQuery object (el), in which you can use jQuery functions to push content. Like the Hello World in this case. 
     render: function(){ 
     this.$el.html("Hello World"); 
     } 
    }); 

var appView = new AppView(); 
} 

    if (Meteor.isServer) { 
    Meteor.startup(function() { 
    Backbone.history.start({pushState: true}); 
     // code to run on server at startup 
     }); 
    } 

답변

0

등뼈가 클라이언트 측 프레임 워크 백본 - 테스트 - app.js. if (Meteor.isServer) {..}에서 백본 관련 코드를 제거하고 if (Meteor.isClient) {..}에 배치하면 코드를 클라이언트 측으로 옮길 필요가 있습니다.

클라이언트 및 서버 폴더를 사용하여 코드를 분할하는 경우 if (Meteor.isServer) {..} 또는 if (Meteor.isClient) {..}을 사용할 필요가 없으면 백본 관련 코드를 클라이언트 폴더에 배치하기 만하면됩니다.

How do I create dynamic URL's with Meteor?

을 또한 수행 meteor-router라는 유성을위한 패키지가 :

나는 클라이언트 측에서 그것을 사용하는 방법에 대한이 질문에 대해 살펴이없는 경우 수행 할 작업의 응용 프로그램은, 백본을 사용하여 생각 페이지 간을 라우팅하는 환상적인 작업으로, 귀하의 요구를보다 편안하게 맞출 수 있습니다. 당신은 더 많은 정보를 찾을 수 있습니다

https://github.com/tmeasday/meteor-router

+0

백본도 서버에서 사용할 수 있습니다! –

+0

그것은 할 수 있습니까 ?? 나는 그것의 가능한 방법에 너무 분실 되었는가?, 나는 그것의 더 추상적 인 조금 (모형, etc.)가 서버에 달릴다는 것을 알고있다 그러나 나는 그것의 여정 조금이 잘 수있다 생각하지 않는다 – Akshat

+0

그럼 몇몇 클라이언트는 재료를 잘한다 라우터, 역사 등 doens't 정말 서버에서 작동합니다. 하지만 백본 모델/컬렉션을 사용하여 서버에서 데이터를 구성 할 수 있습니다. –

관련 문제