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

  • SEARCH
  • Home
  • 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 8672307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:10:16+00:00 2026-06-12T19:10:16+00:00

This is a follow up to a question: KnockoutJS Sortable group observableArray by field

  • 0

This is a follow up to a question: KnockoutJS Sortable group observableArray by field and conditionally sort

There are two further things I am battling to achieve. First when a nested list item is dragged to another list leaving the parent empty I would like to remove the parent. I have done this by creating an afterMove function and checking if the sourceParent length is 0. Then I look through the routes to see if any have an empty tasks array and remove accordingly. I would like to know if this is an efficient solution. I also have to remove the tasks otherwise the tasks subscription adds duplicates when removing scheduled tasks.

Second and most importantly the base object (Task) has an order property. I would like to bind this to the sortable order so that when the tasks are dragged around the Scheduled list the order property is updated. How do I access the order of other list items from the sortable callback?

Please see the following this Fiddle.

Any assistance would be greatly appreciated.

  • 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-06-12T19:10:18+00:00Added an answer on June 12, 2026 at 7:10 pm

    For the first issue, there is a slightly optimized way that you could do it. arg.sourceParent is contained in the tasksByRoute item that you want to remove. The remove function can take a function to run against the items. So, you could write it like:

    self.afterMoveCallback = function(arg) {
        if (arg.sourceParent().length === 0) {
            self.tasksByRoute.remove(function(route) {
               return route.tasks === arg.sourceParent; 
            });
        }
    };
    

    For the second issue, I really like to use an extension that will automatically track the order in an observableArray. It would look something like:

    //track an index on items in an observableArray
    ko.observableArray.fn.indexed = function(prop) {
        prop = prop || 'index';
       //whenever the array changes, make one loop to update the index on each
       this.subscribe(function(newValue) {
           if (newValue) {
               var item;
               for (var i = 0, j = newValue.length; i < j; i++) {
                   item = newValue[i];
                   if (!ko.isObservable(item[prop])) {
                      item[prop] = ko.observable();
                   }
                   item[prop](i);  //add 1 here if you don't want it to be zero based
               }
           }   
       }); 
    
       //initialize the index
       this.valueHasMutated(); 
       return this;
    };
    

    in your case, you would use it like:

    self.scheduledTasks = ko.observableArray([
        new Task(8, 4, "Route 4", "Cust 8", 1),
        new Task(9, 4, "Route 4", "Cust 9", 2),
        new Task(10, 5, "Route 5", "Cust 10")
        ]).indexed("order");
    

    Here is a sample updated with both of these changes: http://jsfiddle.net/rniemeyer/usVKQ/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow up question . So, Java store's integers in two's-complements and
This is a follow up question to Is there a basic Java Set implementation
This is a follow-up question to Is there a difference between throw and throw
This is a follow up question from Calling constructor in return statement . This
This is a follow up question to a previous question I asked about calculating
This is a follow-on question from the one I asked here . Can constraints
This is a follow-up question to ASP.NET How to pass container value as javascript
This is a follow-up question to this question I asked earlier. Btw thanks Neil
this is a follow-up question of mine. Suppose now I have a URL :
This is a follow-up question to the following if you would like to see:

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.