【问题标题】:What is the best high performance Javascript Collections (Collection<T>)? [closed]什么是最好的高性能 Javascript 集合(Collection<T>)? [关闭]
【发布时间】:2012-07-18 10:58:52
【问题描述】:

最重要的起点是没有“添加”选项。我无法识别“拼接”功能!请注意,我接受答案。

我计划在我的下一个项目中使用 knockout.js。但我需要相当于 c# Collection 的 javascript。

-添加 -消除 -包含

我对此要求有两个标准。

  • 生产就绪
  • 性能良好

Javascript 版本

    public class UserResponse
    {
        public Question Question { get; set; }
        public Answer SelectedAnswer { get; set; }
    }
    public class Answer
    {
        public string Name { get; set; }
    }
    public class Question
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public List<Answer> Answers{ get; set; }
    }
    // User dont need to response every question
    public class User
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public List<UserResponse> Responses{ get; set; }
        public void AddResponse(UserResponse response)
        {
            // Find if another answer for response.Question and remove it
            var res=Responses.Where(p => p.Question == response.Question).FirstOrDefault();
            if (res != null)
                Responses.Remove(res);
            // Add new response
            Responses.Add(response);
        }
    }

主干:1 - 淘汰赛:0

http://documentcloud.github.com/backbone/#Collection-add

http://documentcloud.github.com/backbone/#Collection-remove

http://documentcloud.github.com/backbone/#Collection-get

【问题讨论】:

标签: javascript collections knockout.js


【解决方案1】:

使用敲除的可观察数组,或在 ko.utils 命名空间中找到的“扩展”。这通常足以满足我的需要!

http://knockoutjs.com/documentation/observableArrays.html

我会说主干:1 淘汰赛:1(或 2 删除 + removeAll,或 3 反转、排序、移位等)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 2019-11-11
    • 2010-09-09
    • 2011-03-22
    相关资源
    最近更新 更多