我刚刚开始学习nodejs,目前想用jointjs画些流程图。用webstorm建立了一个nodejs的项目结构如下 /test /bin www /node_modules /public /routes index.js users.js /views error.jade index.jade layout.jade app.js pacakge.json
我修改了index.js 来使用jointjs。代码修改后如下: var express = require(‘express’); var router = express.Router(); var joint = require(‘jointjs’); var graph = new joint.dia.Graph;
var el1 = new joint.shapes.basic.Rect({position: {x: 50, y: 50}, attrs: {text: {fill: ‘yellow’}}}); var el2 = new joint.shapes.basic.Rect({position: {x: 300, y: 200}, attrs: {text: {fill: ‘yellow’}}}); var link = new joint.dia.Link({source: {id: el1.id}, target: {id: el2.id}}); graph.addCells([el1, el2, link]);
/* GET home page. */ router.get(’/’, function (req, res, next) { res.render(‘index’, {title: ‘Express’}); });
module.exports = router;
接下来不知道怎么把graph对象传递出去,在jade中渲染。看了stack overflow的帖子就说用graph.toJSON()然后传递到client端。请问有谁知道怎么传递这样一个对象? http://stackoverflow.com/questions/20975782/explain-or-demonstrate-integration-between-jointjs-and-node-js 非常感谢。
res.render不就可以传给模版了吗? From Noder