如何将JointJS与Meteor一起使用?

时间:2015-09-29 21:14:05

标签: javascript backbone.js meteor lodash 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
  });
}

当我运行此操作时,我收到以下错误:

未捕获TypeError:_. merge不是functionjoint.dia.Cell.Backbone.Model.extend.constructor @ joint.js:3831child @ backbone.js:1408(匿名函数)@ joint.js:7436math @ joint。 js:39(匿名函数)@ joint.js:44(匿名函数)@ joint.js?518ac863e9f6f1f9a755394c59ad7d562c084829:11194

Tracker afterFlush功能的异常: ReferenceError:未定义关节     在[object Object]。 (:3000 /应用程序/客户端/流星:/app/client/sampleApp.js:5)

我尝试将sampleApp.html和sampleApp.js放在项目根目录中,也放在client /

中的/ client joint.js中

任何人都处理过这个问题,或者想知道如何解决这个ReferenceError?

编辑:这是JointJS中发生Uncaught TypeError的内容:

// 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);是抛出错误的行

1 个答案:

答案 0 :(得分:0)

原来这是一个依赖性问题,我在安装jointjs-all时通过命令行降级了Backbone和Lodash,这解决了问题。

  

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