让我们把下面作为我的 MVC 模型类:
public class Candidate
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public int Experience { get; set; }
public List<Technology> Technologies { get; set; }
}
public class Technology
{
public string Technology { get; set; }
public int ExperinceInMonths { get; set; }
}
现在,我有一个返回此模态数据的 web api 方法:
public class CandidateController : ApiController
{
// GET api/Candidate
public IEnumerable<Candidate> Get()
{
CandidateServiceClient client = new CandidateServiceClient();
List<Candidate> candidateData = client.GetCandidateData();
if (candidateData == null || candidateData.Count() == 0)
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NoContent));
return candidateData.AsEnumerable();
}
...
使用 Knockout 假设我有这样的 javascript:
$.get(url, function (result) {
candidateViewModel.candidates(result);
ko.applyBindings(candidateViewModel);
});
});
var candidateViewModel = { candidates: ko.observableArray([])};
在此背景下,我的问题是如何构建具有嵌套集合的淘汰视图模型?(如本例中的技术集合。)
寻找类似的东西..
var myViewModel = { firstName: ko.observable(''), lastName: ko.observable(''), .. };
任何帮助是极大的赞赏...