I have a Jason structure that looks like the following, where " status " is sorted Value is "Title": "Title 1", "Status": 1}, {"id": 2, "Title": "Heading 2". {"ID": 5, "Title": "Title 3", "Status": 3}, {"ID": 7, "Title" ":" Title 4 "," status ": 99}]; Knockout-sortable uses index to sort items that can be sorted This is one of my codes. Actually, when an item is dragged to a new position, I want to update the visual model so that I can save the changes to the database. For something like this, I want to add my membership, which observes through an array Starts and correctly sets "index" Here is an extension that will work in case of your use: You would like it to: Here's your updated sample:
ko.observableArray.fn .withIndex = function (prop, startIndex, lastIndex) {// By default use an "index" observation pro = prop || "Index"; // whenever the array changes, indexes make a single pass to update this subscribe (function (newvalue) for {var item; (var i = 0, j = newValue.length; i & lt ; J; i ++) If the observation of the object is not the object then = new value [i]; if (! Item [prop]) {item [prop] = to.horseable ();} / / last Special argument for one item [prop] ((Last index & amp; amp; i === (J-1)); Last index: StartInx + I);}}, this); This return; };
myObservableArray.withIndex ("status", 1, 99);
No comments:
Post a Comment