我定义了一个RequireJs配置来定义路径和填充:
require.config({
// define application bootstrap
deps: ["main"],
// define library shortcuts
paths: {
app: "app"
, jquery: "lib/jquery"
, underscore: "lib/underscore"
, backbone: "lib/backbone"
, bootstrap: "lib/bootstrap"
},
// define library dependencies
shim: {
jquery: {
exports: "$"
},
underscore: {
exports: "_"
},
backbone: {
deps: ["underscore", "jquery"],
exports: "Backbone"
},
bootstrap: {
deps: ['jquery'],
exports: "bootstrap"
},
// main application
app: {
deps: ["backbone"],
exports: "App"
}
}
});
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,当我加载主应用程序(-namespace)时,最后一个"shim"声明应该能够访问主干(并且它是deps).
实际上这不起作用:
require(["app"], function($, _, Backbone, App){
app.router …
Run Code Online (Sandbox Code Playgroud) 我想将express.js与Flatiron的Director(路由器)和Resourceful(ODM)一起使用,因为我需要路由表和清理多数据库模式以及验证的好处.我现在完全切换到Flatiron的原因是,因为我认为它需要更多的时间并且没有太多的doc材料.
然而,这是我在快递中使用导演的当前方式:
var express = require('express')
, director = require('director');
function hello(){
console.log('Success');
}
var router = new director.http.Router({
'/': {
get: hello
}
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用,只给我一个"无法获取/"
那该怎么办?
我不确定如何在模块化(RequireJs)Backbone环境中使用命名空间.
我已经想了一下它怎么可能看起来像,但我完全不能确定这是否是正确的方式.
app.js(由main.js执行)
define('App', ['underscore', 'backbone', 'Router'], function( _, Backbone, Router){
function initialize(){
var app = {}; // app is the global namespace variable, every module exists in app
app.router = new Router(); // router gets registered
Backbone.history.start();
}
return { initialize: initialize }
});
Run Code Online (Sandbox Code Playgroud)
messages.js
define('MessageModel', ['underscore', 'backbone', 'App'], function(_, Backbone, App){
App.Message.Model; // registering the Message namespace with the Model class
App.Message.Model = Backbone.Model.extend({
// the backbone stuff
});
return App;
});
Run Code Online (Sandbox Code Playgroud)
这是正确的方法还是我完全错误的方式(如果是的话请纠正我!)
是否可以在express.js中使用Flatiron的resourcefull(ODM)?
我想检查一个对象是否扩展了另一个对象(true,false):
例:
var BaseObject = function(object) {
this.name = object.name;
this.someFunction = object.someFunction;
this.someOtherProperty = object.someOtherProperty;
};
var ExtendingObject = new BaseObject({
name: "extention",
someFunction: function(value) { return value; },
someOtherProperty = "hi"
});
// some possible function
var extends = isExtending(BaseObject, ExtendingObject);
var isParentof = isParentOf(BaseObject, ExtendingObject);
Run Code Online (Sandbox Code Playgroud)
underscore.js是否提供了这样的功能(我发现没有...)?
我怎样才能进行这样的检查?
Backbone.js在更新的对象而不是PUT上发布POST.
我认为这是因为mongoDB使用_id而不是id.
我怎么说backbone.js使用_id而不是id?
我已经尝试过一些服务器端更改,但我认为主干应该使用另一个属性作为id会更容易. MongoDB:输出'id'而不是'_id'
backbone.js ×3
express ×2
flatiron.js ×2
node.js ×2
requirejs ×2
javascript ×1
mongoose ×1
namespaces ×1