最重要的起点是没有“添加”选项。我无法识别“拼接”功能!通过拼接注意力,我接受了答案。什么是最好的高性能的Javascript Collections(Collection <T>)?
我打算为我的下一个项目使用knockout.js。但我需要JavaScript相当于C#集合。
- 添加 - 删除 - 包含
我有两个指标分析这一要求。
- 生产做好准备
- 良好的性能
的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
什么类型的集合? – casablanca 2012-07-19 09:30:08
Javascript数组到底有多少? – bezmax 2012-07-19 09:31:20
他们没有添加,删除,包含方法或扩展。我写了示例C#代码。 – ozz 2012-07-19 09:45:18