I搜索允许描述数据结构的库。例如,我有一个应用程序。它使用XHR接收数据并检查响应json。
当响应很复杂时,用命令式代码验证它也很复杂。我想以声明的方式描述这样的模型/结构/DTO,然后将其与以下内容一起使用:
var Human = Model.define({
head: Head,
limbs: List(Hand, {min: 0, max: 2}),
...
});
try {
var human = Human.load(anyJsonStringOrObject);
} catch (e) {
console.log('Error loading model');
}
您正在寻找js模型
这里有一些文档中的例子:
var Project = Model("project", function() {
this.extend({
find_by_title: function(title) {
return this.detect(function() {
return this.attr("title") == title
})
}
})
})
Project.find_by_title("stuff")