gpt4 book ai didi

javascript - 将对象 ID 从 success 函数发送到 parse.com 中的另一个函数

转载 作者:行者123 更新时间:2023-11-27 23:23:33 25 4
gpt4 key购买 nike

我在 parse.com 上遇到问题,我需要获取类型的 id 并将其传递给另一个上传图像的函数。然后将 type.id 与图像一起发送到另一个将数据保存到类中的函数。

这是我迄今为止尝试过的方法,但没有成功。

--OnClick 代码

$('#submitId').on("click", function(e, f) {
e.preventDefault();
typeSave(typeid1);

//var objnew1 = typeSave();

console.log("inside onclick " + type2);
var fileUploadControl = $("#profilePhotoFileUpload")[0];
var file = fileUploadControl.files[0];
var name = file.name; //This does *NOT* need to be a unique name
var parseFile = new Parse.File(name, file);
parseFile.save().then(
function() {
//typeSave();
type2 = typeid1;
saveJobApp(parseFile, type2);
console.log("inside save onclick " + type2);
},
function(error) {
alert("error");
}
);
});

-- 键入代码

var type;
var typeid1;
var type2;
function typeSave() {
var type = new Parse.Object("type");
var user = new Parse.Object("magazia");
//var bID = objbID;
//user.id = bID;

var cafebar = document.getElementById('cafe_bar').checked;
if (cafebar) {
var valueCafebar = true;
} else {
var valueCafebar = false;
}
var club = document.getElementById('club').checked;
if (club) {
var valueClub = true;
} else {
var valueClub = false;
}
var restaurant = document.getElementById('restaurant').checked;
if (restaurant) {
var valueRestaurant = true;
} else {
var valueRestaurant = false;
}
var pistes = document.getElementById('pistes').checked;
if (pistes) {
var valuePistes = true;
} else {
var valuePistes = false;
}
type.set("cafebar", valueCafebar);
type.set("club", valueClub);
type.set("restaurant", valueRestaurant);
type.set("pistes", valuePistes);
type.save(null, {
success: function(type) {
//saveJobApp(type.id);
var typeid1 = type.id;
console.log("inside type save " + typeid1);
//return ;

},
error: function(type, error) {
alert('Failed to create new object, with error code: ' + error.description);
}
});
}

-- 将数据发送到 parse.com 类代码

 function saveJobApp(objParseFile, type2) {
var jobApplication = new Parse.Object("magazia");
var email = document.getElementById('email').value;
var name = document.getElementById('name').value;
var description = document.getElementById('description').value;
var website = document.getElementById('website').value;
var phone = document.getElementById('phone').value;
var address = document.getElementById('address').value;
var latlon = document.getElementById('latlon').value;
var area = document.getElementById('area').value;
var value = latlon;
value = value.replace(/[\(\)]/g, '').split(', ');
console.log("inside saveJobApp " + type2);
var x = parseFloat(value[0]);
var y = parseFloat(value[1]);
var point = new Parse.GeoPoint(x, y);
jobApplication.set("image", objParseFile);
jobApplication.set("email", email);
jobApplication.set("phone", phone);
jobApplication.set("address", address);
jobApplication.set("name", name);
jobApplication.set("website", website);
jobApplication.set("description", description);
jobApplication.set("area", area);
jobApplication.set("latlon", point);
jobApplication.set("typeID", type2);
jobApplication.save(null, {
success: function(gameScore) {
// typeSave(jobApplication.id);
},
error: function(gameScore, error) {
alert('Failed to create new object, with error code: ' + error.description);
}
});
}

因此,当我单击按钮首先运行 typesave() 函数时,当它在解析中将类型发布到类型类上时,继续尝试从success 函数并将其发送到 parseFile.save().then然后将 objectFiletype2(即 type.id)发送到 saveJobApp 中将其保存在 magazia

类中

我从console.logs得到的是这个

enter image description here这意味着我的代码发布到类型类并采用 type.id但它不会通过解析文件保存将其发送到 magazia 类。知道我错过了什么吗?

最佳答案

我注意到您的错误不是关于函数,而是关于尝试将 type.id 作为字符串传递,而不是作为 saveJobApp 函数中的函数传递。

如果你尝试这样做

function saveJobApp(objParseFile , objtype) {
var jobApplication = new Parse.Object("magazia");
var type = new Parse.Object("type");

type.id = objtype;
jobApplication.set("typeID", type);

我认为它会起作用。

并将 onclick 和 ParseFile 保存代码更新为此

$('#submitId').on("click", function(e) {
typeSave();
});
function PhotoUpload(objtype){

var fileUploadControl = $("#profilePhotoFileUpload")[0];
var file = fileUploadControl.files[0];
var name = file.name; //This does *NOT* need to be a unique name
var parseFile = new Parse.File(name, file);

parseFile.save().then(
function() {
saveJobApp(parseFile, objtype);
},
function(error) {
alert("error");
}
);
}

以及typeSave()中的成功函数应该是这样的

type.save(null, {
success: function(type) {
PhotoUpload(type.id);
},

希望这有帮助:)

关于javascript - 将对象 ID 从 success 函数发送到 parse.com 中的另一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35174974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com