我有一個像這樣的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是不確定的。