Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用AngularJS从JSON检索项_Json_Angularjs_Asp.net Mvc 4 - Fatal编程技术网

使用AngularJS从JSON检索项

使用AngularJS从JSON检索项,json,angularjs,asp.net-mvc-4,Json,Angularjs,Asp.net Mvc 4,我有一个ASP.NETMVC4应用程序。下面是JSON。我需要的是能够检索具有传递的CS值的特定项的索引。CS值将在ViewBag中传递,JSON也将在下面工厂函数的ViewBag中传递 CDlg.factory("RS", function () { var rs = @Html.Raw(ViewBag.jsonCR); return rs; }); 这是返回的rs: [    {       "CS": "AK",       "CLL": "LN",       "CTC

我有一个ASP.NETMVC4应用程序。下面是JSON。我需要的是能够检索具有传递的CS值的特定项的索引。CS值将在ViewBag中传递,JSON也将在下面工厂函数的ViewBag中传递

CDlg.factory("RS", function () {
    var rs = @Html.Raw(ViewBag.jsonCR);
    return rs;
});
这是返回的rs:

[
   {
      "CS": "AK",
      "CLL": "LN",
      "CTC": [
         {
            "LT": null,
            "CTID": 227322,
            "Hors": 8,
            "Units": 8,
            "Price": 8,
            "CEE": 0
         }
      ]
   },
  {
      "CS": "TX",
      "CLL": "LN",
      "CTC": [
         {
            "LT": null,
            "CTID": 219848,
            "Hours": 8,
            "Units": 8,
            "Price": 6,
            "CEE": 0
         }
      ]
   },
   {
      "CS": "UT",
      "CLL": "LN",
      "CTC": [
         {
            "LT": null,
            "CTID": 219928,
            "Hours": 8,
            "Units": 8,
            "Price": 8,
            "CEE": 0
         }
      ]
   },
   {
      "CS": "VA",
      "CLL": "LN",
      "CTC": [
         {
            "LT": null,
            "CTID": 220041,
            "Hours": 8,
            "Units": 8,
            "Price": 0,
            "CEE": 0
         }
      ]
   },
   {
      "CS": "VT",
      "CLL": "LN",
      "CTC": [
         {
            "LT": null,
            "CTID": 220344,
            "Hours": 8,
            "Units": 8,
            "Price": 12,
            "CEE": 0
         }
      ]
   }
]
这是我需要填充的范围变量:

$scope.selectedCS = ?????
如果我传入“TX”,我需要它返回完整对象:

  {
      "CS": "TX",
      "CLL": "LN",
      "CTC": [
         {
            "LT": null,
            "CTID": 219848,
            "Hours": 8,
            "Units": 8,
            "Price": 6,
            "CEE": 0
         }
      ]
   }

只需迭代并检查:

for (var i = 0; i < rs.length; i++) {
    if (rs[i].CS == passedInValue) {
        return rs[i];
    }
}
for(变量i=0;i
您是否考虑过使用ng repeat和filter?请参见此处:设置一个不会反映在UI中的范围变量。