我在项目中使用angularjs.
我从服务器获取了一系列对象.每个对象包含很少的属性,其中一个属性是date属性.
这是我从服务器获得的数组(在json中):
[
{
"Address": 25,
"AlertType": 1,
"Area": "North",
"MeasureDate": "2019-02-01T00:01:01.001Z",
"MeasureValue": -1
},
{
"Address": 26,
"AlertType": 1,
"Area": "West",
"MeasureDate": "2016-04-12T15:13:11.733Z",
"MeasureValue": -1
},
{
"Address": 25,
"AlertType": 1,
"Area": "North",
"MeasureDate": "2017-02-01T00:01:01.001Z",
"MeasureValue": -1
}
.
.
.
]
Run Code Online (Sandbox Code Playgroud)
我需要从阵列中获取最新日期.
从对象数组中获取最新日期的优雅方法是什么?
我正在尝试根据参数将模板加载到Angular应用程序中.这将是一个ng-foreach:
<body ng-app="MyApp" ng-controller="ExampleController as example">
<div ng-repeat="item in example.items" class="someClass" ng-switch="item.type">
<!-- load a different template (partial) depending on the value of item.type -->
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
小提琴: https ://jsfiddle.net/rsvmar2n/1/
我可以以某种方式这样做吗?我在考虑使用ng-switch:https://jsfiddle.net/rsvmar2n/6/
但我确信有一种更有棱角的方式来做到这一点.
编辑:我不想为我要加载的每个部分做一个http请求(我认为ngInclude会这样做.
Edit2:使用ng-include和缓存模板结束.https://jsfiddle.net/rsvmar2n/24/
我试图在Symfony 控制器中返回BinaryFileResponse响应,但它要求路径或File对象.问题是我通过SOAP服务获取文件,它创建了一个像这样的对象:+ + + . filenamebase64 encoded contentmimeextra stuff
我真的不想将它保存到磁盘然后创建响应...
也许我现在被蒙蔽了,但有没有办法在不创建磁盘文件的情况下发送它?
这是行动:
public function downloadAction($hash){
$document = $this->get('soap_services.document_service')->findDocument($hash);
return $this->file($SymfonyFileObjectOrPath, $fileName);
}
Run Code Online (Sandbox Code Playgroud)
该$document对象提供以下相关方法:getMime,getName,getContent.
这就是我想要用来做出响应而不创建File对象(以及它暗示的物理文件).