我有一个样式(服装)模型和图像模型和一对多样式< =图像的关系。更新关系将覆盖所有的关系,而且最新的记录
我有一个jQuery的Cloudinary部件上传图片,然后我试图更新的URL图像的图像关系。然后打算将这些图像显示在表格中。
然而,当我用我的代码更新的关系,它不仅节省了对关系的最新StyleCode。
所以,如果我救一个图像,然后又一个,图像表云从这个:
Image URL Style
http://abc 1234
这个
Image URL Style
http://abc <blank>
http://xyz 1234
我的第一个问题是,如何将关系实际工作?它似乎依靠我的StyleCode保持记录关系。我会认为它会被_key .....?
其次,你有没有什么可以在我的代码,发现这可能是覆盖以前的StyleCode?
服务器端代码
function saveImageToStyle(images, styleCode) {
var imgs = [];
images.forEach(function(image)
{
var imageRecord = app.models.Images.newRecord();
imageRecord.ThumbnailURL = image.thumbnail_url;
imageRecord.ImageURL = image.url;
imageRecord.Path = image.path;
imageRecord.ImageName = image.original_filename;
imgs.push(imageRecord);
});
app.saveRecords(imgs);
var query = app.models.Styles.newQuery();
query.filters.StyleCode._equals = styleCode; // is it this???
var styleRecord = query.run()[0];
styleRecord.Images = imgs;
app.saveRecords([styleRecord]);
}
客户端代码
function saveStyleImages(images) {
var styleCode = app.datasources.Styles.item.StyleCode; // is there a better way to get the current StyleCode?
var status = app.pages.StyleEdit.descendants.Status;
google.script.run
.withFailureHandler(function(error) {
status.text = error.message;
})
.withSuccessHandler(function(result) {
status.text = images + "success";
})
.saveImageToStyle(images, styleCode);
}
谢谢!我styleRecord.Images.push做到了(IMGS):) – Samuurai
从谷歌员工的官员说,修复你需要做的是这样的: 为(VAR I = 0; I
Samuurai