Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:51:44+00:00 2026-05-26T14:51:44+00:00

I am trying to have the functionality of the jQuery selectable list when using

  • 0

I am trying to have the functionality of the jQuery selectable list when using KnockoutJS, but can’t get it to work.

Using Custom Bindings I was successful in transforming ul element in a selectable one and creating events handlers for the selected and unselected events. But what do I pass to my ViewModel functions which maintain the selected elements?

Here is my code so far: http://jsfiddle.net/QCmJt/

I am new to all this, so maybe I am approaching this the wrong way…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:51:45+00:00Added an answer on May 26, 2026 at 2:51 pm

    Ok, I figured a way to pass the data bound to the selected item:

    $(ui.selected).tmplItem().data when selecting and
    $(ui.selected).tmplItem().data when unselecting.

    Here the updated fiddle: http://jsfiddle.net/8RnxC/

    Custom binding looks like:

    ko.bindingHandlers.selectable = {
            init: function(element, valueAccessor) {
                $(element).attr("id", "selectable").selectable({
                    selected: function(event, ui) {
                        vm.selectRequest($(ui.selected).tmplItem().data);
                    },
                    unselected: function(event, ui) {
                        vm.unselectRequest($(ui.unselected).tmplItem().data);
                    }
                });
            }
        };
    

    And my view model:

    function viewModel() {
            // Data
            this.requests = ko.observableArray([]);
            this.selectedRequests = ko.observableArray([]);
    
            // Behaviours
            this.selectRequest = function(request) {
                this.name = "othername";
                // Add to array if not already there.
                if ($.inArray(request, this.selectedRequests()) === -1) {
                    this.selectedRequests().push(request);
                }
                var self = this;
    
            };
            this.unselectRequest = function(request) {
                // Remove from the array.
                this.selectedRequests().splice($.inArray(request, this.selectedRequests()), 1);
            };
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a custom field type with jQuery autocomplete functionality. But I'm
HI, I'm trying to get accordion like functionality without using jQuery's UI accordion feature.
I have a question about some functionality I'm trying to add to my jQuery
I'm trying to get better at using Jquery and therefore would like feedback on
I'm using Rails 3.1 and trying to add some ajax functionality (using jquery +
I'm trying to make some ajax-functionality in my web application, but I cannot get
I'm using the jquery sortable functionality to sort a list of items in my
I'm trying to implement more/less functionality using the official jquery-tmpl plugin. I've looked at
I am having a few issues trying to get some basic jquery functionality working
I'm using jQuery tablesorter to add functionality to a couple of tables. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.