我是knockoutjs中的新手,我看到了一个示例,它通过选择选项中索引的下拉值来上下移动数组值.但它的问题是它们不能正确地移动值.更改选择框中的数组位置选项后,将更改..
var viewModel = function() {
var self = this;
var Item = function(name, pos) {
this.name = ko.observable(name);
this.position = ko.observable(pos);
var oldPosition = pos;
this.position.subscribe(function(newValue) {
self.reposition(this, oldPosition, newValue);
oldPosition = newValue;
}, this);
};
this.items = [
new Item("item Three", "3"),
new Item("item One", "1"),
new Item("item Two", "2"),
new Item("item Five", "5"),
new Item("item Four", "4"),
new Item("item Six", "6")
];
self.orderedItems = ko.computed(function() {
return ko.utils.arrayFilter(this.items, function(item) {
return true;
}).sort(function(a, b) {
return a.position() …
Run Code Online (Sandbox Code Playgroud)我真的很喜欢链接Array.prototype.map
, filter
并reduce
定义数据转换.不幸的是,在最近涉及大型日志文件的项目中,我无法再多次循环遍历我的数据......
我想创建一个链.filter
和.map
方法的函数,而不是立即映射数组,组成一个循环数据一次的函数.即:
const DataTransformation = () => ({
map: fn => (/* ... */),
filter: fn => (/* ... */),
run: arr => (/* ... */)
});
const someTransformation = DataTransformation()
.map(x => x + 1)
.filter(x => x > 3)
.map(x => x / 2);
// returns [ 2, 2.5 ] without creating [ 2, 3, 4, 5] and [4, 5] in between
const myData = …
Run Code Online (Sandbox Code Playgroud) 我正在使用淘汰赛js,我发现diffcult绑定数据,而在ajax get方法,我已经创建了模型,viewModel和ajax函数,我有相同的js文件中的ajax方法,我创建了viewModel我正在调用页面上的ajax加载并试图用konckout js绑定我的html,userModel is undefined
如果我this.name = ko.observale(result[0].name)
在ajax调用之前给出,我收到错误,在ajax之后调用它name is undefined
需要帮助
<html>
<head>
<script src="js/jquery1.9.js"></script>
<script src="js/knockout-3.3.0.js"></script>
<script src="js/knockout.mapping.js"></script>
<script src="model/usermodel.js"></script>
</head>
<body>
<div>
<h1><span data-bind="text:user().name"></span></h1>
<h1><span data-bind="text:user().userName"></span></h1>
</div>
<script src="ViewModel/userDetailsViewModel.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
////Model////
function userModel(result) {
var self = this;
this.name = ko.observable(result[0].name); /// give me error undefined before the ajax call and after ajax call i get the value in result
this.userName = ko.observable();
}
/////View Model////
var result
var userDetailsViewModel = …
Run Code Online (Sandbox Code Playgroud) 我有一个jQuery数组 ["3434", "3433"]
我想这样做 [3434, 3433]