我有一个名为'sails-mongo'的模块,我想使用以下命令将其更新到最新版本:
npm update sails-mongo --save
Run Code Online (Sandbox Code Playgroud)
我也试过卸载然后重新安装.我试着sails-mongo@latest
和sails-mongo@beta
.
问题:GitHub上的当前版本(master)package.json(https://github.com/balderdashy/sails-mongo/blob/master/package.json)文件具有:
"dependencies": {
"async": "~0.2.9",
"lodash": "~2.4.1",
"mongodb": "1.4.2",
"waterline-errors": "~0.10.0"
},
Run Code Online (Sandbox Code Playgroud)
并在一个正在更新
"dependencies": {
"async": "0.2.10",
"underscore": "1.5.2",
"underscore.string": "2.3.3",
"mongodb": "~1.3.23"
},
Run Code Online (Sandbox Code Playgroud)
获得master分支的唯一方法是使用该命令 npm install git+https://github.com/balderdashy/sails-mongo
为什么不sails-mongo@latest
安装master分支?
我在教师(一)和儿童(很多)之间有一对多的关系.
如果我做:
Teacher.destroy(teacherId).exec(function(err){});
Run Code Online (Sandbox Code Playgroud)
孩子们不会被自动删除.
这是一个错误还是我应该手动删除它们?如果这不是一个错误,那么不删除孩子的解释是什么?
我的 SailsJS 应用程序中有以下模型,我想在字段“room_name”和“school_id”上添加复合唯一键。
我目前做的是从 mongo 运行这个命令:
db.room.ensureIndex({'room_name': 1, 'school_id':1}, {unique: true})
Run Code Online (Sandbox Code Playgroud)
问题 1 我做得对吗?
问题 2 是否可以修改我的模型,使其自动调用此命令而无需手动修改 mongodb(从 mongo 命令行)?
这是模型
module.exports = {
schema: true,
attributes: {
room_name: {
type: 'string',
required: true
},
school_id: {
type: 'string',
required: true
},
children_count: {
type: 'integer',
required: true
}
}
}
Run Code Online (Sandbox Code Playgroud) 根据Mocha文档,"Mocha测试连续运行",这意味着按照它们的定义顺序.
我的问题是:是什么让异步(完成回调)测试不同于同步?
我希望能够在调用任何函数之前自动调用一个函数。__callStatic的问题在于它仅在该方法不存在时才运行。
请参见下面的代码。
我想让always_run()在静态类中调用的任何函数之前运行。
class Test {
public static function __callStatic($method, $parameters){
echo __CLASS__ . "::" . $method;
if (method_exists(__CLASS__, $method)) {
self::always_run();
forward_static_call_array(array(__CLASS__,$method),$args);
}
}
public static function always_run() {
echo "always_run";
}
public static function my_func() {
echo "myfunc was called";
}
}
Test::my_func();
// OUTPUT: always_run myfunc wascalled
Run Code Online (Sandbox Code Playgroud) 有一个模型,所有其他模型都假设它存在.它应该在调用任何API函数之前初始化.
我这样做的方式(它不起作用):
1)在api/models中定义模型,我们称之为Location.js
2)将以下内容添加到bootstrap.js
var Locations = require('../api/models/Locations.js');
module.exports.bootstrap = function (cb) {
// seed the database with Locations
var locationsObj = {
country: 'Australia',
states: ['Brisbane', 'Perth', 'Sydney']
};
Location.create(locationsObj, function locationsObj(err, locations) {
if (err) {
cb(err);
}
console.log('locations created: ', locations);
});
}
Run Code Online (Sandbox Code Playgroud)
问题1 这是进行初始数据库播种的正确方法吗?
我收到此错误:
Locations.create(locationsObj, function locationsObj(err, locations) {
^
TypeError: Object #<bject> has no method 'create'
Run Code Online (Sandbox Code Playgroud)
问题2 bootstrap 的cb功能如何工作?如果出现错误怎么办?
我正在使用sails.js(节点js框架).
我正在尝试JSON.stringify其中一个对象,但是当我这样做时,它省略了一个字段(下面的房间数组).
这是console.log(对象)给我的:
[ { rooms: [ [Object], [Object] ],
state: '53df76c278999310248072c6',
name: 'Sydney Center',
menuItems: null,
createdAt: Mon Aug 04 2014 23:42:08 GMT+0300 (Jerusalem Summer Time),
updatedAt: Mon Aug 04 2014 23:42:08 GMT+0300 (Jerusalem Summer Time),
id: '53dff0205c89c03428a31cee' },
{ rooms: [ [Object], [Object], [Object] ],
state: '53df76c278999310248072c6',
createdAt: Mon Aug 04 2014 23:43:21 GMT+0300 (Jerusalem Summer Time),
menuItems: null,
name: 'Batata Center',
updatedAt: Mon Aug 04 2014 23:51:11 GMT+0300 (Jerusalem Summer Time),
id: '53dff06a5c89c03428a31cf3' } ] …
Run Code Online (Sandbox Code Playgroud) 我使用bootstrap selectpicker(http://silviomoreto.github.io/bootstrap-select/)
我试图通过以下方式扩大选择框大小:
<select class="selectpicker input-lg">...</select>
Run Code Online (Sandbox Code Playgroud)
如果我在select输入中添加"input-lg",selectpicker会覆盖它,并且不会调整选择框的大小.
如何克服这个问题?