2017-01-02 61 views
0

我下载并安装了“Totaljs Eshop”,并注意到产品创建不允许我定义产品选项(即产品颜色)。创建nosql模型,尝试构建具有可变产品选项的产品模式

我进入了NoSQL嵌入式数据库,查看了models/product.js文件。

我看到:

NEWSCHEMA('Product').make(function(schema) { 

schema.define('id', 'String(20)'); 
schema.define('pictures', '[String]'); 
schema.define('reference', 'String(20)'); 
schema.define('category', 'String(300)', true); 
schema.define('manufacturer', 'String(50)'); 
schema.define('name', 'String(50)', true); 
schema.define('price', Number, true); 
schema.define('priceold', Number); 
schema.define('description', String, true); 
schema.define('availability', 'String(40)'); 
schema.define('template', 'String(30)'); 
schema.define('body', String); 
schema.define('pictures2', '[String]'); 
schema.define('istop', Boolean); 
schema.define('isnew', Boolean); 
schema.define('linker', 'String(50)'); 

我尝试添加以下代码:

schema.define('nicstrength', 'Array(0mg, 1.5mg, 3mg, 6mg, 9mg, 12mg)') 

我得到的错误说:

======= 2017-01-02 02:50:21: Error: Schema: "nicstrength.Array(0mg, 1.5mg, 3mg, 6mg, 9mg, 12mg)" not found in "default". Error: Schema: "nicstrength.Array(0mg, 1.5mg, 3mg, 6mg, 9mg, 12mg)" not found in "default". 
at SchemaBuilderEntity.default (/Users/student/Dev/eshop/node_modules/total.js/builders.js:1138:23) 
at SchemaBuilderEntity.get.SchemaBuilderEntity.read (/Users/student/Dev/eshop/node_modules/total.js/builders.js:832:27) 
at Controller.$get.Controller.$read (/Users/student/Dev/eshop/node_modules/total.js/index.js:10247:19) 
at Controller.json_products_read (/Users/student/Dev/eshop/controllers/api.js:73:7) 
at Subscribe.doExecute (/Users/student/Dev/eshop/node_modules/total.js/index.js:9754:23) 
at Subscribe.execute (/Users/student/Dev/eshop/node_modules/total.js/index.js:9680:8) 
at Subscribe.doAuthorization (/Users/student/Dev/eshop/node_modules/total.js/index.js:9796:8) 
at /Users/student/Dev/eshop/node_modules/total.js/index.js:9707:9 
at F.onAuthorize (/Users/student/Dev/eshop/models/users.js:324:3) 
at Subscribe.prepare (/Users/student/Dev/eshop/node_modules/total.js/index.js:9694:3) 

我非常新的后端,所以我如果这是一个微不足道的问题,请道歉。

这里是我的库中的链接,我分叉最初的开源项目

https://github.com/akadop/eshop

回答

1

你必须定义一个正确的模式类型和Array(0mg, 1.5mg, 3mg, 6mg, 9mg, 12mg)无效Total.js模式类型。这里是所有支持的类型:https://docs.totaljs.com/latest/en.html#api~SchemaBuilder

快速修复:

schema.define('nicstrength', ['0mg', '1.5mg', '3mg', '6mg', '9mg', '12mg']); 

所以字段需要包含仅从定义的值的一个值。

+0

谢谢!在我这样做之后,我是否继续对产品模板进行必要的调整? –

+0

当然 - 您可以使用“String(5)”类型而不是定义的值。我建议学习更多的Total.js框架。 –

+0

再次感谢。我现在正在查看文档,并且我相信我更了解它。我将如何向用户提供他们从中选择的选项列表?表单按钮是否必须位于特定产品的自定义代码中? –