我有这个模特
import {Entity, model, property} from '@loopback/repository';
@model()
export class Coupon extends Entity {
@property({
id: true,
type: 'string',
required: false,
mongo: {
columnName: '_id',
dataType: 'ObjectID',
},
})
id: string;
@property({
type: 'string',
required: true,
})
name: string;
@property({
type: 'number',
required: true,
})
maximumUses: number;
@property({
type: 'string',
required: true,
})
type: string;
@property({
type: 'number',
required: true,
})
amount: number;
@property({
type: 'number',
required: true,
})
maximumUsesPerPerson: number;
@property({
type: 'string',
required: true,
})
validFrom: string;
@property({
type: 'string',
required: true,
})
validTo: string;
@property({
type: 'number',
required: true,
})
currentTotalUses: number;
@property({
type: 'array',
itemType: 'string',
})
certainDays?: string[];
@property({
type: 'array',
itemType: 'string',
})
certainHours?: string[];
@property({
type: 'boolean',
required: true,
})
valid: boolean;
@property({
type: 'array',
itemType: 'string',
})
clients?: string[];
@property({
type: 'disabled',
required: true,
})
disabled: boolean;
constructor(data?: Partial<Coupon>) {
super(data);
}
}
模型存储库
import {DefaultCrudRepository} from '@loopback/repository';
import {Coupon} from '../models';
import {TestDataSource} from '../datasources';
import {inject} from '@loopback/core';
export class CouponRepository extends DefaultCrudRepository<
Coupon,
typeof Coupon.prototype.id
> {
constructor(
@inject('datasources.test') dataSource: TestDataSource,
) {
super(Coupon, dataSource);
}
}
现在以下功能应该可以正常工作
await this.couponsRepo.create({ name: 'string',
maximumUses: 0,
maximumUsesPerPerson: 0,
amount: 0,
validFrom: 'string',
validTo: 'string',
type: 'percentage',
valid: true,
currentTotalUses: 0,
disabled: false });
但会引发此错误
ReferenceError:未定义g 在新的禁用状态下(在createModelClassCtor(../LBIssue/lbissue/node_modules/loopback-datasource-juggler/lib/model-builder.js:678:21),:10:27处评估)
仅产生此错误,请创建一个空的loopback 4项目 然后将优惠券模型=加上我提供的代码
答案 0 :(得分:0)
您的模型定义有误。
看到这个
<select name="Source_Station" style="width:20%; border: 3px solid red;" id="txt1" onchange="{% url 'Home:LoadData' %}">
{% for data in stations %}
<option value="{{ data.Station_Name }}">{{ data.Station_Name }}
</option>
{% endfor %}
</select>
类型不能被禁用。应该是
@property({
type: 'disabled',
required: true,
})
disabled: boolean;