Javascript I';我不确定这个项目发生了什么,它在本地工作,但在服务器上有问题
我正在尝试将一个项目从本地移动到服务器,但它不像在本地那样工作,我不知道发生了什么。我有产品,当我编辑它们时,它不会像本地那样从数据库中获取信息,它会将2个非常重要的数字作为0,当我知道数据库中没有这些数字作为0时,价格就无法计算 这是它为产品带来的信息Javascript I';我不确定这个项目发生了什么,它在本地工作,但在服务器上有问题,javascript,vue.js,Javascript,Vue.js,我正在尝试将一个项目从本地移动到服务器,但它不像在本地那样工作,我不知道发生了什么。我有产品,当我编辑它们时,它不会像本地那样从数据库中获取信息,它会将2个非常重要的数字作为0,当我知道数据库中没有这些数字作为0时,价格就无法计算 这是它为产品带来的信息 [ { "country": { "id": 1, "name": "COSTA RICA", "currency_symbol": "CRC" }, "country_id": 1, "margin": 0, "fi": 0 }, { "c
[ { "country": { "id": 1, "name": "COSTA RICA", "currency_symbol": "CRC" }, "country_id": 1, "margin": 0, "fi": 0 },
{ "country": { "id": 2, "name": "NICARAGUA", "currency_symbol": "COR" }, "country_id": 2, "margin": 0, "fi": 0 },
{ "country": { "id": 3, "name": "HONDURAS", "currency_symbol": "HNL" }, "country_id": 3, "margin": 0, "fi": 0 } ]
对于数据库中的此产品,其边距和fi为
product_id: 1
country_id: 1
margin: 0.65
fi: 0.50
product_id: 1
country_id: 2
margin: 0.65
fi: 0.50
product_id: 1
country_id: 3
margin: 0.65
fi: 0.50
“编辑产品”是“创建模型”的克隆,由于某些原因,它没有提供应有的信息
这是打开“创建”和“编辑”对话框的函数
showDialog(model) {
if (this.processing) {
return;
}
if (model) {
let cloneModel = {...model};
this._formatModel(cloneModel);
this.actionText = 'Actualizar';
this.form = cloneModel
} else {
this.dialogTitle = 'Nuevo';
this.actionText = 'Agregar';
this._isNew();
if (this.form.id) {
this._resetForm();
this.$refs.form.resetFields()
}
}
this.dialogTitle = this._getDialogTitle(this.form);
this.dialogVisible = true
}
_formatModel(model) {
this.productCategories = [];
this.loadingResource = true;
this.$http.post(this.baseUrl + '/show/' + model.id).then(
(res) => {
this.model.export_factors = this.countries.map((country) => {
let result = res.body.export_factors.filter((item) => item.country_id === country.id);
let margin = 0;
let fi = 0;
if (result.length > 0) {
margin = result[0].margin;
fi = result[0].fi;
}
return {
country: country,
country_id: country.id,
margin: margin,
fi: fi,
}
});
this.model.prices = this.countries.map((country) => {
let result = res.body.prices.filter((item) => item.country_id === country.id);
let resultExport = res.body.export_factors.filter((item) => item.country_id === country.id);
let price = 0;
if (result.length > 0) {
price = (this.form.cif / resultExport[0].margin) / resultExport[0].fi;
}
return {
country: country,
country_id: country.id,
price: price.toFixed(2),
}
});
this.productCategories = res.body.categories.map((category) => {
category.fields = category.fields.map(item => {
item.allFields = [item.field];
return item;
});
return category;
});
this.form.tags = res.body.tags;
this.form.sizes = res.body.sizes;
this.loadingResource = false;
},
(res) => {
this.loadingResource = false;
this.dialogVisible = false;
this.$message.error(parseError(res)[0])
}
)
},
_isNew() {
this.model.prices = this.countries.map((country) => {
return {
country: country,
country_id: country.id,
price: 0,
}
});
this.model.export_factors = this.countries.map((country) => {
return {
country: country,
country_id: country.id,
fi: 0,
margin: 0
}
});
this.productCategories = [];
}
可能会发生什么情况?过滤器函数内部的比较可能有问题。在比较两个id时,您可以将id解析为整数,如下所示。我只是在纠正你的_格式模型
_formatModel(model) {
this.productCategories = [];
this.loadingResource = true;
this.$http.post(this.baseUrl + '/show/' + model.id).then(
(res) => {
this.model.export_factors = this.countries.map((country) => {
let result = res.body.export_factors.filter((item) => parseInt(item.country_id) === parseInt(country.id));
let margin = 0;
let fi = 0;
if (result.length > 0) {
margin = result[0].margin;
fi = result[0].fi;
}
return {
country: country,
country_id: country.id,
margin: margin,
fi: fi,
}
});
this.model.prices = this.countries.map((country) => {
let result = res.body.prices.filter((item) => parseInt(item.country_id) === parseInt(country.id));
let resultExport = res.body.export_factors.filter((item) => parseInt(item.country_id) === parseInt(country.id));
let price = 0;
if (result.length > 0) {
price = (this.form.cif / resultExport[0].margin) / resultExport[0].fi;
}
return {
country: country,
country_id: country.id,
price: price.toFixed(2),
}
});
this.productCategories = res.body.categories.map((category) => {
category.fields = category.fields.map(item => {
item.allFields = [item.field];
return item;
});
return category;
});
this.form.tags = res.body.tags;
this.form.sizes = res.body.sizes;
this.loadingResource = false;
},
(res) => {
this.loadingResource = false;
this.dialogVisible = false;
this.$message.error(parseError(res)[0])
}
)
},您显示的响应是json响应。在转换为json格式之前,您能检查并显示响应吗?另外,我认为您显示的vuejs代码不完整。能否显示正确的vuejs代码,如初始化所有内容和所有内容?@KCP我显示的是关系带来的结果,我添加了另一个函数_formatModel我认为
内部过滤器后的结果
值\u formatModel
函数返回为空。你能在过滤器后面控制台并查找结果值吗?@KCP它在服务器上返回数组(0),但在本地项目上返回数据。如果你控制台res.body.export\u factors,是否有任何数据?