整合自己的小工具angularjs
问题描述:
*检查dashboardCtrl.js和整合与最终的JSON数据格式以下窗口小部件(开始getDashboard()函数:整合自己的小工具angularjs
- 第一
- 谢胜利
- 第三*
我应该写这样的吗?
$ http.get(Dashboard)function(){}?或功能getDashboard(){} 如果有人知道如何整合,请发送给我链接,谢谢
答
您没有足够的信息来帮助我们。但是,如果您被要求将某些内容整合/合并到 JSON中,请使用$ http.post()。举个例子:
// Some data to send
var my_data = {"widgets":[{"widget1":""},{"widget2":""},{"widget3":""}],"JSONfile":"file.json"};
$http.post(url,my_data).then(function(result){
/* Success */
}, function(error){
/* Error */
});
打开和修改JSON,你可以使用PHP:
<?php
/* Get the data from POST request
$dataReceived = file_get_contents('php://input');
$myFile = json_decode($dataReceived);
$myWidget = $myFile->widgets;
$JSON_file_name = $myFile->JSONfile;
*/
$content = json_decode(file_get_contents($JSON_file_name), true);
$content['content'][] = ['widget'=>$myWidget];
$newJsonString = json_encode($content, JSON_UNESCAPED_SLASHES);
file_put_contents($JSON_file_name, $newJsonString);
?>
从JSON检索数据:
$http.get(url).then(function(result){
$scope.my_data = result.data;
}, function(error){
/* Error */
$scope.my_data = null;
});
谢谢你,现在我undertand一切 – MargeKh