locked
WinJS.Binding.List move method bug? RRS feed

  • Question

  • Hi,

    I have a listView application.

    I used use list.move method by calling myList.move(15, 5) to move the item on index 15 to the item to index 5.

    According to http://msdn.microsoft.com/en-us/library/windows/apps/hh700768.aspx, it should do what I expected. 

    However, it doesn't move the list to 5, but it moves the list to index 0, the top of my list. 

    So why is that happening?



    Louis

    Monday, March 19, 2012 11:16 PM

Answers

  • Hi,

    I'm unable to reproduce this problem. Below is my test code:

          var myList = new WinJS.Binding.List();
               for (var i = 0; i < 20; i++) {
                   myList.push(i);

               }
               console.log("===Before Move===");
               myList.forEach(function (element) { console.log(element); });
             
               myList.move(15, 5);
               console.log("===After Move===");
               myList.forEach(function (element) { console.log(element);});

    Does above code work for you?


    Allen Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 20, 2012 8:50 AM
  • Thanks Allen.

    I understand this snippet is barely helpful. Unfortunately I can't come up with a demo to repro them quickly because this is only a small part of a large project and I don't know which part causes this to fail.

    So, I don't use other code to update this name property in the list, but I update some other properties of the list. How will that impact the usage of the move method? Wouldn't the updated list still be a WinJS.Binding.List object which is illegible to call .move method? Is there any usage limitation on this method?

    Thanks,


    Louis

    Hi Louis,

    The reason I say it may be caused by the update is from below result we can see the "name_5" appears twice:

    ============ after move: name_2  ================  //comment: isn't this suppose to be name_5?
    name_5
    //comment: why is it moved to the top of the list?
    name_1
    name_2
    name_3
    name_4
    name_5
    name_6
    name_7
    name_8

    So it doesn't look like a move. I guess the move action is correct but before you show it in console the properties are updated by other code logic. So I suggest you add another property for the item that is not used in other code to check whether it's update or move issue. (Do you bind the name property? It should also be considered as "used")

    Another possibility is there is a bug in WinJS.Binding.List. I would suggest you compare the value of the properties of the WinJS.Binding.List in working and failing scenarios. Maybe from differences of the properties you could find the key that could reproduce the problem. If you still cannot create a repro is it possible for you to send the entire project to me? My email is allenc at microsoft.com


    Allen Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.






    • Edited by Allen Chen - MSFT Friday, March 23, 2012 1:41 AM
    • Marked as answer by Jie Bao Tuesday, April 10, 2012 3:34 AM
    Friday, March 23, 2012 1:35 AM

All replies

  • Hi,

    I'm unable to reproduce this problem. Below is my test code:

          var myList = new WinJS.Binding.List();
               for (var i = 0; i < 20; i++) {
                   myList.push(i);

               }
               console.log("===Before Move===");
               myList.forEach(function (element) { console.log(element); });
             
               myList.move(15, 5);
               console.log("===After Move===");
               myList.forEach(function (element) { console.log(element);});

    Does above code work for you?


    Allen Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 20, 2012 8:50 AM
  • Yes. It does work. 

    But it doesn't work in my version of it. I think it is mostly likely my problem. I will keep look into it and see what I can get out of this.

    Thanks.


    Louis

    Tuesday, March 20, 2012 5:40 PM
  • Hi Allen,

    I have spent another day on this problem. I am 100% sure that I am calling move on a WinJS.Binding.List object. Could you please suggest me a few reason that it doesn't more to the right place? I print out the whole list (using forEach) before and after the "move" call and in the console I can see it doesn't move the item. 

    Thanks,


    Louis

    Wednesday, March 21, 2012 3:07 PM
  • Hi Louis,

    Please post a very simple repro of your problem.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, March 21, 2012 6:58 PM
    Moderator
  • Code:
    //print out the name of the item (at index) that's going to be moved
    console.log("============ before move: " + myList.getAt(index).name + " ================ ");
    // print out the mylist
    myList.forEach(function (item) {
    	console.log(item.name);
    });
    // move the item from index=index to index=2
    myList.move(index, 2);
    //After the move, print out the name of the item (at index = 2) 
    console.log("============ after move: " + myList.getAt(2).name + "  ================");
    // print out the mylist
    myList.forEach(function (item) {
            console.log(item.name);
    });
    console.log("============ DONE move ================");
    
    Output:
    ============ before move: name_5 ================
    name_1
    name_2
    name_3
    name_4
    name_5
    name_6
    name_7
    name_8
    name_9
    ============ after move: name_2  ================  //comment: isn't this suppose to be name_5?
    name_5 //comment: why is it moved to the top of the list?
    name_1
    name_2
    name_3
    name_4
    name_6
    name_7
    name_8
    ============ DONE move ================

    I don't think this helps too much, but myList is 100% a WinJS.Binding.List with groups because it is myList.dataSource is the itemDataSource of my listview.


    Louis


    • Edited by Louis_PiG Friday, March 23, 2012 7:12 PM
    Thursday, March 22, 2012 12:10 AM
  • Hi,

    At first glance of this behavior a possible reason is you use other code to update the name of the item in your List. Could you try to add a new property for the item that you can make sure is not used anywhere else in your other code and check that property instead of the name property? You can also post a demo that can reproduce the problem. The code snippet doesn't quite help for me to troubleshoot.


    Allen Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 22, 2012 3:12 AM
  • Thanks Allen.

    I understand this snippet is barely helpful. Unfortunately I can't come up with a demo to repro them quickly because this is only a small part of a large project and I don't know which part causes this to fail.

    So, I don't use other code to update this name property in the list, but I update some other properties of the list. How will that impact the usage of the move method? Wouldn't the updated list still be a WinJS.Binding.List object which is illegible to call .move method? Is there any usage limitation on this method?

    Thanks,


    Louis

    Thursday, March 22, 2012 4:10 PM
  • Thanks Allen.

    I understand this snippet is barely helpful. Unfortunately I can't come up with a demo to repro them quickly because this is only a small part of a large project and I don't know which part causes this to fail.

    So, I don't use other code to update this name property in the list, but I update some other properties of the list. How will that impact the usage of the move method? Wouldn't the updated list still be a WinJS.Binding.List object which is illegible to call .move method? Is there any usage limitation on this method?

    Thanks,


    Louis

    Hi Louis,

    The reason I say it may be caused by the update is from below result we can see the "name_5" appears twice:

    ============ after move: name_2  ================  //comment: isn't this suppose to be name_5?
    name_5
    //comment: why is it moved to the top of the list?
    name_1
    name_2
    name_3
    name_4
    name_5
    name_6
    name_7
    name_8

    So it doesn't look like a move. I guess the move action is correct but before you show it in console the properties are updated by other code logic. So I suggest you add another property for the item that is not used in other code to check whether it's update or move issue. (Do you bind the name property? It should also be considered as "used")

    Another possibility is there is a bug in WinJS.Binding.List. I would suggest you compare the value of the properties of the WinJS.Binding.List in working and failing scenarios. Maybe from differences of the properties you could find the key that could reproduce the problem. If you still cannot create a repro is it possible for you to send the entire project to me? My email is allenc at microsoft.com


    Allen Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.






    • Edited by Allen Chen - MSFT Friday, March 23, 2012 1:41 AM
    • Marked as answer by Jie Bao Tuesday, April 10, 2012 3:34 AM
    Friday, March 23, 2012 1:35 AM
  • Oh Sorry, that was my bad. There is actually no name_5 there between name_4 and name_6. 

    I pasted an extra name_5 there when I tried not to expose the content of the real output. 

    Sorry about that and I will update my previous reply.


    Louis

    Friday, March 23, 2012 7:12 PM
  • Hi Louis,

    Is there any progress? Could you send me a repro project? If it contains sensitive data you can replace it with fake ones.


    Allen Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 26, 2012 2:00 AM