1

I have

 KnockoutObservableArray<string> 

and I show this list by

<div data-bind="template: { foreach: City, afterAdd: showElement, beforeRemove: hideElement }">.

If I added a new city to this list it shows on end of list, but I need show new city as first item. How can I do that?

Peter
  • 13
  • 3
  • 1
    possible duplicate of [How to add/insert an item into an ObservableArray at a certain position with Knockout.js](http://stackoverflow.com/questions/7317907/how-to-add-insert-an-item-into-an-observablearray-at-a-certain-position-with-kno) – Tanner Sep 19 '14 at 11:13
  • Working version based on answer in duplicate: http://jsfiddle.net/bxfXd/4506/ – Tanner Sep 19 '14 at 11:14

1 Answers1

0

to insert into the collection use

viewModel.City.unshift("new City");
Marv
  • 441
  • 2
  • 14