Search code examples
knockout.jsknockout-2.0knockout-mvc

Knokout new on item on top of list


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?


Solution

  • to insert into the collection use

    viewModel.City.unshift("new City");