rniemeyer / knockout-sortable

A Knockout.js binding to connect observableArrays with jQuery UI sortable functionality
MIT License
547 stars 128 forks source link

anonymous templates will break in next version of knockout #199

Closed fastfasterfastest closed 4 years ago

fastfasterfastest commented 5 years ago

FYI, knockout commits https://github.com/knockout/knockout/commit/0f0cb8e23fa3f01a9f845cb539f2b6521322664f and https://github.com/knockout/knockout/commit/a93358fb9e2e2ef285985df2015a442ad83fd09a which is addressing https://github.com/knockout/knockout/issues/2446 breaks the knockout-sortable binding when it is used with anonymous templates and the value is an object, e.g.

<ul data-bind="sortable: { data: items }">
  <li data-bind="text: name"></li>
</ul>

The knockout-sortable binding currently passes { name: undefined, … } as the value to the template binding when it is used with anonymous templates and the value is an object, and the above mentioned commits (not yet in a public release of knockout) have changed how knockout handles a value that has a name property.

See https://jsfiddle.net/fastfasterfastest/3rekjytw/

fastfasterfastest commented 5 years ago

In case those knockout commits appear in a future public knockout release, I believe the following change in prepareTemplateOptions will avoid this issue: Change result.name = options.template; to if (options.hasOwnProperty('template')) { result.name = options.template; } or if (options.template) { result.name = options.template; }

rniemeyer commented 5 years ago

@fastfasterfastest - thanks for the heads up

rniemeyer commented 4 years ago

Thanks for the heads up so long ago @fastfasterfastest. Version 1.2.0 is out with this fix.