Update ObservableArray - Knockout.js

Ruby

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());
Vitaliy Khudonogov

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Knockout JS failed to update observableArray

From Dev

Knockout: Update item in an observableArray

From Dev

knockout.js: No concat on observableArray

From Dev

Custom filtering knockout js observableArray

From Dev

Knockout.js contenteditable observablearray

From Dev

knockout.js: No concat on observableArray

From Dev

Knockout js observableArray is not getting updated

From Dev

knockout observableArray elements don't update view

From Dev

Knockout update observableArray item does not reflect in UI?

From Dev

Knockout.js - Registering to change in observableArray

From Dev

Knockout JS - Modifying properties of items in observableArray

From Dev

Knockout.js - Registering to change in observableArray

From Dev

knockout.js observableArray computed value

From Dev

knockout.js observableArray changes not reflecting in UI

From Dev

Sorting observableArray with added item Knockout JS

From Dev

Knockout does not update UI when observableArray is a property of other model

From Dev

My Observablearray in knockout foreach binding doesn't update?

From Dev

My Observablearray in knockout foreach binding doesn't update?

From Dev

Knockout ObservableArray.replace() function does not update 'optionsText' binding

From Dev

Can not find index form observablearray knockout.js

From Dev

knockout.js validation on observableArray to require all items (no empty fields)

From Dev

Knockout not create and observableArray

From Dev

Filtering an observableArray in Knockout

From Dev

Knockout observableArray is not binding correctly

From Dev

Knockout observableArray push not working

From Dev

Load Knockout observableArray not working

From Dev

Knockout observableArray not updating UI

From Dev

Update an array item in knockout js

From Dev

Knockout move observableArray item down

Related Related

  1. 1

    Knockout JS failed to update observableArray

  2. 2

    Knockout: Update item in an observableArray

  3. 3

    knockout.js: No concat on observableArray

  4. 4

    Custom filtering knockout js observableArray

  5. 5

    Knockout.js contenteditable observablearray

  6. 6

    knockout.js: No concat on observableArray

  7. 7

    Knockout js observableArray is not getting updated

  8. 8

    knockout observableArray elements don't update view

  9. 9

    Knockout update observableArray item does not reflect in UI?

  10. 10

    Knockout.js - Registering to change in observableArray

  11. 11

    Knockout JS - Modifying properties of items in observableArray

  12. 12

    Knockout.js - Registering to change in observableArray

  13. 13

    knockout.js observableArray computed value

  14. 14

    knockout.js observableArray changes not reflecting in UI

  15. 15

    Sorting observableArray with added item Knockout JS

  16. 16

    Knockout does not update UI when observableArray is a property of other model

  17. 17

    My Observablearray in knockout foreach binding doesn't update?

  18. 18

    My Observablearray in knockout foreach binding doesn't update?

  19. 19

    Knockout ObservableArray.replace() function does not update 'optionsText' binding

  20. 20

    Can not find index form observablearray knockout.js

  21. 21

    knockout.js validation on observableArray to require all items (no empty fields)

  22. 22

    Knockout not create and observableArray

  23. 23

    Filtering an observableArray in Knockout

  24. 24

    Knockout observableArray is not binding correctly

  25. 25

    Knockout observableArray push not working

  26. 26

    Load Knockout observableArray not working

  27. 27

    Knockout observableArray not updating UI

  28. 28

    Update an array item in knockout js

  29. 29

    Knockout move observableArray item down

HotTag

Archive