2015-09-29 19 views
0

我想從jointjs教程中運行示例應用程序,這是迄今爲止我所擁有的。如何將JointJS與流星結合使用?

1)sampleApp.html

<head> 
    <title>sampleApp</title> 

</head> 

<body> 
    <h1>Welcome to Meteor!</h1> 

    {{> hello}} 
</body> 

<template name="hello"> 
    <div></div> 
</template> 

2)sampleApp.js

if (Meteor.isClient) { 

    Template.hello.onRendered(function() { 

     var graph = new joint.dia.Graph; 

     var paper = new joint.dia.Paper({ 
     el: this.$('div'), 
     width: 600, 
     height: 200, 
     model: graph, 
     gridSize: 1 
     }); 

     var rect = new joint.shapes.basic.Rect({ 
     position: { x: 100, y: 30 }, 
     size: { width: 100, height: 30 }, 
     attrs: { rect: { fill: 'blue' }, text: { text: 'my box', fill: 'white' } } 
     }); 

     var rect2 = rect.clone(); 
     rect2.translate(300); 

     var link = new joint.dia.Link({ 
     source: { id: rect.id }, 
     target: { id: rect2.id } 
     }); 

     graph.addCells([rect, rect2, link]); 
    }); 
} 

if (Meteor.isServer) { 
    Meteor.startup(function() { 
    // code to run on server at startup 
    }); 
} 

當我運行此我得到以下錯誤:

遺漏的類型錯誤:_.merge不一個functionjoint.dia.Cell.Backbone.Model.extend.constructor @ joint.js:3831child @ backbone.js:1408(匿名函數)@ joint.js:7436math @ joint.js:39(匿名函數)@joint.js :44(匿名功能)@聯合。 JS 518ac863e9f6f1f9a755394c59ad7d562c084829:11194

與從跟蹤afterFlush功能

異常: 的ReferenceError:接頭不在[對象的對象]中定義 。 (:3000/app/client/meteor:/app/client/sampleApp.js:5)

我已經嘗試在項目根目錄中放置sampleApp.html和sampleApp.js,並且還在/ client joint.js中客戶端/

任何人都已經處理了這個問題或有任何想法如何解決這個ReferenceError?

編輯:這是其中未捕獲的類型錯誤發生JointJS的內容:

// joint.dia.Cell base model. 
// -------------------------- 

joint.dia.Cell = Backbone.Model.extend({ 

    // This is the same as Backbone.Model with the only difference that is uses _.merge 
    // instead of just _.extend. The reason is that we want to mixin attributes set in upper classes. 
    constructor: function(attributes, options) { 

     var defaults; 
     var attrs = attributes || {}; 
     this.cid = _.uniqueId('c'); 
     this.attributes = {}; 
     if (options && options.collection) this.collection = options.collection; 
     if (options && options.parse) attrs = this.parse(attrs, options) || {}; 
     if (defaults = _.result(this, 'defaults')) { 
      //<custom code> 
      // Replaced the call to _.defaults with _.merge. 
      attrs = _.merge({}, defaults, attrs); 
      //</custom code> 
     } 
     this.set(attrs, options); 
     this.changed = {}; 
     this.initialize.apply(this, arguments); 
    }, 

ATTRS = _.merge({},缺省值,ATTRS);是引發錯誤的行

+0

從錯誤消息中可以看到Underscore未被加載到頁面上。 jointjs似乎在使用Underscore來處理'_.merge(...)',但沒有找到它。這導致'聯合'沒有被定義,因爲它初始化失敗。這樣簡單嗎? –

+0

_.merge(...)的代碼是Backbone.js的一部分,我沒有觸及,我不確定它引用的是什麼。 – nerfdoit

+0

對於未來的搜索者,Backbone.js確實依賴於單獨提供的Underscore :.從文檔:「骨幹的唯一硬依賴是Underscore.js(> = 1.7.0)。」 –

回答

0

原來,這是一個依賴性問題,我在安裝jointjs-all時通過命令行降級了Backbone和Lodash,並解決了問題。

meteor add mxmxmx:jointjs-all --allow-incompatible-update