我想以某种方式能够在我的TypeScript类上静态设置枚举,并能够通过导出类在内部和外部引用它.我对TypeScript很新,所以我不确定这个的正确语法,但下面是一些伪代码(扩展了Backbone模型)我希望能够用来实现我需要的东西. ..
class UnitModel extends Backbone.Model {
static enum UNIT_STATUS {
NOT_STARTED,
STARTED,
COMPLETED
}
defaults(): UnitInterface {
return {
status: UNIT_STATUS.NOT_STARTED
};
}
isComplete(){
return this.get("status") === UNIT_STATUS.COMPLETED;
}
complete(){
this.set("status", UNIT_STATUS.COMPLETED);
}
}
export = UnitModel;
Run Code Online (Sandbox Code Playgroud)
我需要能够在这个类中引用枚举,但我还需要能够在类之外引用枚举,如下所示:
import UnitModel = require('path/to/UnitModel');
alert(UnitModel.UNIT_STATUS.NOT_STARTED);//expected to see 0 since enums start at 0
Run Code Online (Sandbox Code Playgroud) 我正在开发一个支持许多不同语言环境的站点.我们的下一个地方是希伯来语,这是一种从右到左的语言.我正在设置dir=rtl和lang=heHTML元素,并且某些事情转移(他们应该).
很多网站都使用绝对定位设置左值的元素.有没有办法在你处于rtl模式时这样做,它会将它切换为正确的值?
我知道我可以rtl在我的html元素上有一个类,并且当该类存在时执行css覆盖,但是项目非常大,并且手动搜索所有这些事件并不会很有趣.
我有一个名为“ Users”的猫鼬模式,其中有一个“ Roles”子文档作为其变量之一,如下所示:
var UserSchema = new mongoose.Schema({
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
roles: [ { type: Number, ref: 'Role' } ]
});
var RoleSchema = new mongoose.Schema({
_id: Number,
name: { type: String, required: true, unique: true },
description: { type: String, required: true }
});
Run Code Online (Sandbox Code Playgroud)
我想创建一个Mongoose查询,该查询将找到所有Roles.name为“ admin”或“ owner”的用户。我曾尝试使用此查询,但我认为该查询会起作用,但使用该where...in零件时没有任何用户。
var roles = ["owner", "admin"];
User.find()
.populate('roles')
.where('roles.name').in(roles)
.sort({'_id': 1})
.exec(function (err, users) {
res.send(users);
});
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我我的逻辑错在哪里吗?
javascript ×3
backbone.js ×1
class ×1
css ×1
enums ×1
html ×1
jquery ×1
mongodb ×1
mongoose ×1
node.js ×1
typescript ×1