var assayData = '[{"AssayCode":"0001C","AssayName":"Assay A","Comments":"Here is the comment"},{"AssayCode":"0002D","AssayName":"Assay B","Comments":"Here is the comment for assay b"}]';
console.log(assayData);
//using the ko.mapping.fromJSON to make your rawData properties into observables, so the list updates with any changes
//download from http://knockoutjs.com/documentation/plugins-mapping.html
var assays = ko.mapping.fromJSON(assayData);
console.log(assays());
var viewModel ={};
var selectedAssay=ko.observable(); //initialize the selectedAssay which will be set by the addNewAssay function call later
//just for debugging, subscribe to the selectedAssay so we can see when it's been changed
selectedAssay.subscribe(function(){
console.log('selected assay changed');
console.log(selectedAssay().AssayName());
});
var addNewAssay=function(){
//create a new Assay initializing each property to a ko.observable so the data in the list updates when the data changes in the edit screen
var newAssay ={"AssayCode":ko.observable(""),"AssayName":ko.observable(""),"Comments":ko.observable("")};
assays.push(newAssay);
selectedAssay(newAssay);
}
//call addNewAssay to set the edit form to a new assay record at initialisation
//addNewAssay();
viewModel.Assays=assays;
viewModel.selectedAssay=selectedAssay;
viewModel.addNewAssay=addNewAssay;
ko.applyBindings(viewModel);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.