2016-02-03 19 views
1

我有parse.com一個問題,其中i到採取類型的ID並將它傳遞給其上載的圖像的另一功能。然後在圖像中取出type.id並將其發佈到另一個將數據保存到類中的函數。從成功函數發送對象ID的另一功能在parse.com

這是我試過至今沒有成功。

- 的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()功能,當它張貼在解析類型類的類型後,採取從成功的功能type.id並將其發送到parseFile.save().then 然後發送objectFiletype2(這是type.id)它saveJobApp並把它保存在類magazia

我從console.logs得到的是這種

enter image description here 這意味着我的代碼後到類型類並採取類型.id 但它不會將它發送到magazia類通過parsefile保存。 任何想法我缺少什麼?

回答

1

我注意到你的錯誤是不是功能,但對試圖通過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); 
      }, 

希望這有助於:)

+0

其實你是對的,我不得不通過它像一個對象我檢查出你的代碼,你在哪裏正確! –