You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the collection option only knows how to deal with strings, as viewModel[collection] is used to access the desired array. This works fine, except in cases where you need to use Knockout's $data context property as the collection option. While using $data as the collection may sound strange, I have a use case for it (I'm inside a KO with binding, and at that point, $data is my collection).
My proposal to fix this is to make the binding capable of accepting references to the collection itself for the collection option. The diff for my commit is at the bottom - I've done some testing, and things seem to work fine. I'll be testing further tomorrow - just wanted to get the idea out there.
Proposed Example HTML 1 (reference collection by name)
<tableclass="table-ordered"><thead><tr><thdata-bind="orderable: { collection: 'Collection', field: 'FieldName' }">Column Header</th>
(rest of table header here)
</tr><tbodydata-bind="foreach: $data">
(table body context here)
</tbody></thead></table>
Proposed Example HTML 2 (reference collection by object)
<tableclass="table-ordered"><thead><tr><thdata-bind="orderable: { collection: Collection, field: 'FieldName' }">Column Header</th>
(rest of table header here)
</tr><tbodydata-bind="foreach: $data">
(table body context here)
</tbody></thead></table>
Proposed Example HTML 3 (reference collection by $data property
Looks good to me. It adds more flexibility to binding without breaking changes. Please submit PR. If you can also add example to readme it would be great.
Everything seems to work pretty well. The only thing that would be nice is figuring out a way to allow computed observable arrays to be used for the collection option. This currently doesn't work because you can't write to a computed unless it has a write callback.
Currently, the collection option only knows how to deal with strings, as
viewModel[collection]
is used to access the desired array. This works fine, except in cases where you need to use Knockout's $data context property as the collection option. While using$data
as the collection may sound strange, I have a use case for it (I'm inside a KOwith
binding, and at that point, $data is my collection).My proposal to fix this is to make the binding capable of accepting references to the collection itself for the collection option. The diff for my commit is at the bottom - I've done some testing, and things seem to work fine. I'll be testing further tomorrow - just wanted to get the idea out there.
Proposed Example HTML 1 (reference collection by name)
Proposed Example HTML 2 (reference collection by object)
Proposed Example HTML 3 (reference collection by $data property
Proposed Script
Commit Diff
The text was updated successfully, but these errors were encountered: