window.batchViewModel.currentCategory.Products()[0].UniCodeID.subscribe(function (newValue) {
getProductUniCode(newValue);
});
function getProductUniCode(uniCodeId) {
// If new value is empty don't call service just return
if (!uniCodeId) {
window.batchViewModel.currentCategory.Products()[0].ProductUniCode("");
return false;
}
var result = dataFromRemoteService(uniCodeId);
updateProductCategoryCode(result);
}
function updateProductUniCode(newUniCodeFromService) {
// Other code here
// Set related value in KO based on data from remote service.
window.batchViewModel.currentCategory.Products()[0].ProductUniCode(newUniCodeFromService);
return true;
}
var productCount = window.batchViewModel.currentCategory.Products().length;
for (var i = 0; i < productCount; i++) {
window.batchViewModel.currentCategory.Products()[i].UniCodeID.subscribe(function (newValue) {
getProductUniCode(newValue, i);
});
}
function getProductUniCode(uniCodeId, productIndex) {
// If new value is empty don't call service just return
if (!uniCodeId) {
window.batchViewModel.currentCategory.Products()[productIndex].ProductUniCode("");
return false;
}
var result = dataFromRemoteService(uniCodeId);
updateProductCategoryCode(result, productIndex);
}
function updateProductUniCode(newUniCodeFromService, productIndex) {
// Other code here
// Set related value in KO based on data from remote service.
window.batchViewModel.currentCategory.Products()[productIndex].ProductUniCode(newUniCodeFromService);
return true;
}
--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
function initBatchBinding() {
var mapping = {
'Products': {
create: function (options) {
return new MYAPP.model.Product(options.data);
}
}
};
var boundData = {
currentBatch: ko.mapping.fromJS(window.defaultBatch, mapping)
};
return boundData;
}
this.UniCodeID.subscribe(function(newUniCodeID) {
if (!newUniCodeId) {
this.ProductUniCode("");
} else {
var idx = this.$index; // this.$index doesn't work - how do I get index here?
var result = dataFromRemoteService(uniCodeId);
updateProductUniCode(result, productIndex);
}
}, this);
updateProductUniCode(result, idx);