function myFunc() {
alert(this.value);
return true;
}
function MyModel() {
var self = this;
var data = [{
Id:1,
text: "answer1",
value: "value1"},
{
Id:2,
text: "answer2",
value: "value2"}];
self.selectedValue = ko.observable('x');
function updateQuestions(data) {
//The following mapping allows the detection of new, modified and deleted objects by their appropriate key.
var mapping = {
'answers': {
key: function (data) {
return ko.utils.unwrapObservable(data.Id); //The id property of the answer
}
}
};
//Create a viewModel that contains observable properties created automatically from the returned JSON data.
self.answers = ko.mapping.fromJS(data, mapping);
}
updateQuestions(data);
}
$(document).ready(function() {
ko.applyBindings(new MyModel());
//$("div.answers").buttonset();
//$("input:radio").on("click",myFunc);
});
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.