0


Actually I have 2 problems in my code, here is the link to my jsFiddle Not Working Demo.
Problem 1: I can't drag and drop any item from one list to another.
Problem 2: After drag and drop will work, how can I change my specific item from array?

Here is my observable array:

self.customExportFileArray = ko.observableArray([
      {
        "IncludeInExportConversionTypesSelectList" :
          [
            {
              "ConversionGroupID" : "1",
              "Title" : "Quote Start - Auto"
            },
            {
              "ConversionGroupID" : "2",
              "Title" : "Quote Finish - Auto"
            },
            {
              "ConversionGroupID" : "3",
              "Title" : "Sales Data"
            }
          ],
        "ChooseFromConversionTypesSelectList" : [],
        "FileName" : "Template1"
      },
      {
        "IncludeInExportConversionTypesSelectList":
          [
            {
              "ConversionGroupID" : "1",
              "Title" : "Quote Start - Auto"
            },
            {
              "ConversionGroupID" : "2",
              "Title" : "Sales Data"
            }
          ],
        "ChooseFromConversionTypesSelectList":
          [
            {
              "Title" : "Quote Finish - Auto"
            }
          ],
        "FileName" : "Template2"
      }
    ]);


So, for example, I chose 'Template1' from my dropdown, selectedTemplate property will takes second item from array and after I move items from left to the right sides and vise versa IncludeInExportConversionTypesSelectList (right side of list) and ChooseFromConversionTypesSelectList (left side of list) arrays should be updated, and clicking on Grab all data from specific template button it should return me updated specific array (according to pre-selected dropdown control).

Does anyone know what am I doing wrong? Because I had working code before adding dropdown.

Any help would be highly appreciated.
Thanks in advance.

4

1 回答 1

1

The sortable plugin expects the arrays that you are dragging items between to be observableArrays. In your case, only your overall array is observable.

You would want to make sure that the individual arrays are observable. Here is a sample: http://jsfiddle.net/rniemeyer/bSuJx/

    self.customExportFileArray = ko.observableArray([
      {
        "IncludeInExportConversionTypesSelectList" : ko.observableArray(
          [
            {
              "ConversionGroupID" : "1",
              "Title" : "Quote Start - Auto"
            },
            {
              "ConversionGroupID" : "2",
              "Title" : "Quote Finish - Auto"
            },
            {
              "ConversionGroupID" : "3",
              "Title" : "Sales Data"
            }
          ]),
        "ChooseFromConversionTypesSelectList" : ko.observableArray([]),
        "FileName" : "Template1"
      },
      {
        "IncludeInExportConversionTypesSelectList": ko.observableArray(
          [
            {
              "ConversionGroupID" : "1",
              "Title" : "Quote Start - Auto"
            },
            {
              "ConversionGroupID" : "2",
              "Title" : "Sales Data"
            }
          ]),
        "ChooseFromConversionTypesSelectList": ko.observableArray(
          [
            {
              "Title" : "Quote Finish - Auto"
            }
          ]),
        "FileName" : "Template2"
      }
    ]);

If this represents data coming from the server, then you would likely need to process it to make observableArrays before applying bindings.

于 2012-12-18T15:38:59.633 回答