【问题标题】:Integration own widget angularjs集成自己的小部件 angularjs
【发布时间】:2018-03-20 09:27:17
【问题描述】:

*检查dashboardCtrl.js并将以下小部件与最终的JSON数据格式集成(从getDashboard()函数开始:

  • 首先
  • 第三个*

我应该这样写吗?

$http.get(Dashboard)function(){}?或函数 getDashboard(){} 如果有人知道如何集成,请给我发链接,谢谢

【问题讨论】:

    标签: angularjs widget integration


    【解决方案1】:

    您没有足够的信息让我们帮助您。但如果您被要求将一些内容整合/合并到 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;
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-11
      • 2012-08-25
      • 2011-03-23
      • 2011-04-14
      • 1970-01-01
      相关资源
      最近更新 更多