0

http://jsfiddle.net/kcFpS/5/

Each row will have an 'Edit' button. On clicking this,

  1. It should fill the row values in the respective textboxes below the table. eg: 'productName' will fill in txtName, etc.

  2. Editing the text in the textbox will reflect the change in the table.

But the foll. code is not working :

<td>
   <button data-bind="click: $parent.editProduct">Edit</button>
</td>

function Product(Name,Qty) {
            pname = ko.observable(Name);
            qty = ko.observable(Qty);
        }

        var ViewModel = function () {
            var self = this;
            self.products = ko.observableArray([{ pname: 'Mobile', qty: 5 },
                                            { pname: 'Car', qty: 1}]);

            self.SelectedItem = ko.observable(new Product());                

            self.editProduct = function (item) {
                self.SelectedItem(item);
            };
};  

        ko.applyBindings(new ViewModel());
2
  • what's the problem? your jsfiddle is working fine. But you don't have to do attr: {disable:...}, knockout provided disable and enable binding out of the box. knockoutjs.com/documentation/disable-binding.html Commented Jul 7, 2014 at 1:39
  • Sorry. Wrong Url.Updated Commented Jul 7, 2014 at 7:34

1 Answer 1

1

If I correctly understood your question. You need to implement editing array of data. I sketched for you an example:

var ViewModel = function() {
var $scope = this;

$scope.array = ko.observableArray([]);
$scope.array.push({ name: ko.observable('Ben'), lastName: ko.observable('Afleck'), editMode: ko.observable(false) });
$scope.array.push({ name: ko.observable('Tom'), lastName: ko.observable('Cruse'), editMode: ko.observable(false) });

$scope.toggleEdit = function(data) {
if (data.editMode()) {
data.editMode(false);
console.log(data.name());
console.log(data.lastName());
}
else
data.editMode(true);
};
return $scope;
};
var vm = new ViewModel();
ko.applyBindings(vm);

http://jsfiddle.net/9X3er

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.