我有一个像这样的JS对象。
function Product() {
this.prop1 = 1;
this.prop2 = 2;
}
function Work(values) {
this.prodID = 0;
this.anotherProp = 1;
this.updateProductID = function(newProdID) {
var sourceURL = "the URL here";
alert("ID is: " + this.product.prodID); //displays 0
$.getJSON(sourceURL, function(data) {
//I want to update the property like this
this.product.prodID = data.Products.ProductID;
})
};
我所试图做的是使一个JSON调用并填充工作对象的实例的product.ProdID财产,但我总是得到this.product是不确定的。