【发布时间】:2013-05-14 17:29:44
【问题描述】:
AngularJS 无法绑定到值类型模型,如下所述:
- https://github.com/angular/angular.js/issues/1267
- Modifying an array within an object that's displayed in a ng-repeat
在服务器端,我只有一个字符串列表:
[Route("/path/{Id}", "GET, OPTIONS")]
public class MyModel
{
public int Id { get; set; }
public List<string> SomeListItems { get; set; }
}
当我想通过 ng-repeat 将(使用 ng-model 到输入)绑定到列表项时,它不起作用,因为 ServiceStack 将它们序列化为字符串数组。
是否可以告诉 ServiceStack 序列化程序序列化和反序列化列表和字典作为可与 AngularJS 绑定一起使用的对象?
例如
{
"id": 1,
"someListItems": [
{ "value": "Item1" },
{ "value": "Item2" },
...
]
}
字典也是如此。
我找到的唯一解决方案是返回 List<KeyValuePair<string, string>>,但这在服务器端非常难看。
【问题讨论】:
标签: c# json rest angularjs servicestack