私の ApiController メソッドは、次の形式で JSON を返します。
"[{\"Category\":{\"CategoryType\":{\"Categories\":[{\"Client\":{\"Categories\":[{\"CategoryType\":{\"Categories\":[{\"Controls\":[],\"Risks\":[{\"Controls\":[],\"PCRMaps\":[],\"Id\":3,\"Title\":\"Risk with ID\",\"Description\":\"Test\",\"CategoryId\":80, etc etc
次のように、この JSON オブジェクトからドロップダウン リストをレンダリングする AngularJS コードがあります。
<select ng-model="newRisk.ClientId" id="ddlClient" name="ddlClient">
<option></option>
<option ng-repeat="client in clients" value="{{client.Id}}">{{client.Name}}</option>
</select>
しかし、私が得ているエラーは、この JSON が不適切に解釈されていることを示しているようです:
Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed.
Use 'track by' expression to specify unique keys.
Repeater: client in clients track by client.Id,
Duplicate key: undefined, Duplicate value: "["
私を怒らせているのはその最後の行です - 重複した値 "["
ここにコントローラーコードがあります。非常に簡単です:
[HttpGet]
public string GetAll()
{
return JsonConvert.SerializeObject(clientRepo.GetAll(),
Formatting.Indented,
new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
}
JSON オブジェクトを返す前に、追加のフォーマット手順を実行する必要がありますか?