[英]modify local variable in javascript
the descriptionPercentagesStr variable is not modified in the success queryExt.first. 在成功queryExt.first中不会修改descriptionPercentagesStr变量。
I think it is a syntax error but can not find. 我认为这是语法错误,但找不到。
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);
Note that the first
query function is asynchronous. 请注意,第
first
查询函数是异步的。 The success
and failure
functions are its callbacks and are called at a later arbitrary time when the query completes. success
和failure
函数是其回调,在查询完成后的任意任意时间调用。 They are not called sequentially as with the rest of your code. 不会像其他代码一样顺序调用它们。 So the order of operations in your code is as follows:
因此,代码中的操作顺序如下:
descriptionPercentagesStr
to "inicial" descriptionPercentagesStr
设置为“ inicial” ProductExtendidoClass
for the matching idProduct
(results not received yet) ProductExtendidoClass
查询匹配的idProduct
(结果尚未收到) descriptionPercentagesStr
(returns "inicial") descriptionPercentagesStr
PercentagesStr(返回“ inicial”) descriptionPercentagesStr
is set to the result descriptionPercentagesStr
设置为结果 You can verify this behavior by adding alert(descriptionPercentagesStr);
您可以通过添加
alert(descriptionPercentagesStr);
来验证此行为alert(descriptionPercentagesStr);
into the success
callback function. 进入
success
回调函数。 It should output the result from Parse. 它应该从Parse输出结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.