在成功queryExt.first中未修改descriptionPercentagesStr变量。
我认为这是语法错误但无法找到。
var ProductExtendidoClass = Parse.Object.extend("Product");
var productExtObj = new ProductExtendidoClass();
var idProduct =this.model.attributes.id;
var queryExt = new Parse.Query(ProductExtendidoClass);
descriptionPercentagesStr="inicial";
queryExt.equalTo("idProduct", idProduct);
queryExt.first({
success: function(productExtObj) {
if (productExtObj!=null)// se tiene el producto
{
);
$("input[name=description_percentages]").val(productExtObj.get("descriptionPercentages"));
descriptionPercentagesStr=productExtObj.get("descriptionPercentages");
}
else
{
//alert("lengt es menor o igual a 0");
}
// Successfully retrieved the object.
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
alert(descriptionPercentagesStr);
答案 0 :(得分:1)
请注意,first
查询功能是异步的。 success
和failure
函数是其回调函数,并在查询完成后的任意时间调用。与其余代码一样,它们不会按顺序调用。因此,代码中的操作顺序如下:
descriptionPercentagesStr
设置为" inicial" ProductExtendidoClass
以查找匹配的idProduct
(尚未收到结果)descriptionPercentagesStr
(返回" inicial")descriptionPercentagesStr
设置为结果您可以通过将alert(descriptionPercentagesStr);
添加到success
回调函数中来验证此行为。它应该从Parse输出结果。