KnockoutJS 排序多维 ko.observableArray
我真的很难对 ko.observableArray 进行排序。在过去的一个小时里我一直在寻找解决方案,并且我非常确信我正在按照书本去做。
基本上,问题似乎来自于元素数组在排序时实际上并不存在的事实。每个项目都由一个函数表示,我认为该函数允许 KnockoutJS 侦听突变...但它对我没有多大帮助:)
链接到 JSfiddle | http://jsfiddle.net/farina/W7HJP/
查看我的小提琴并单击排序链接。正如您所看到的,您将得到一堆 NaN 值,而不是实际排序。
任何帮助将不胜感激!
I'm really struggling to sort a ko.observableArray. I've been searching for solutions for the past hour, and I'm pretty convinced I'm doing it by the book.
Basically the problem seems to come from the fact that the array of elements doesn't actually exist at sort time. Each item is represented by a function which I assume allows KnockoutJS to listen for mutations...but it's not helping me much :)
Link to JSfiddle | http://jsfiddle.net/farina/W7HJP/
Check out my fiddle and click the sort link. As you can see you'll get a bunch of NaN values instead of actual sorting.
Any help would be greatly appreciated!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您访问可观察值的值时,您需要将其作为具有零参数的函数来调用。
所以:
所以,按照你的排序,你会这样做:
http://jsfiddle.net/rniemeyer/W7HJP/ 10/
When you access an observable's value, you need call it as a function with zero arguments.
So:
So, in your sort, you would do:
http://jsfiddle.net/rniemeyer/W7HJP/10/