Created
January 16, 2014 09:23
-
-
Save yanhua365/8452066 to your computer and use it in GitHub Desktop.
KnockoutJS 交换数组里元素的数据(实现上移,下移功能)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function FilesViewModel() { | |
var self = this; | |
self.fileServers =ko.observableArray([{"url":"http://192.168.109.130/4337/"},{"url":"http://192.168.109.122/3366/"}}); | |
self.upFileServer = function() { | |
var index = self.fileServers.indexOf(this); | |
if(index > 0){ | |
var temp = self.fileServers()[index-1]; | |
self.fileServers.splice(index-1, 1); | |
self.fileServers.splice(index, 0, temp); | |
} | |
}; | |
self.downFileServer = function() { | |
var index = self.fileServers.indexOf(this); | |
if(index < self.fileServers().length-1){ | |
var temp = self.fileServers()[index]; | |
self.fileServers.splice(index, 1); | |
self.fileServers.splice(index+1, 0, temp); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment