Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
Javascript js可以轻松切换JSON文件_Javascript_Json_Angularjs - Fatal编程技术网

Javascript js可以轻松切换JSON文件

Javascript js可以轻松切换JSON文件,javascript,json,angularjs,Javascript,Json,Angularjs,我有一个单一JSON文件的工作示例,现在我想添加两个类似的JSON文件,以便在它们之间切换 Script.js: var app = angular.module('app', []); app.controller('AppCtrl', ['$scope', '$http', function(scope, http){ scope.mode = 'official'; // dict = [{'name': 'official', 'file': 'schedule31

我有一个单一JSON文件的工作示例,现在我想添加两个类似的JSON文件,以便在它们之间切换

Script.js:

var app = angular.module('app', []);

app.controller('AppCtrl', ['$scope', '$http', function(scope, http){

    scope.mode = 'official';

    // dict = [{'name': 'official', 'file': 'schedule314_official.json'}, {'name': 'personal', 'file': 'schedule314.json'}];
    dict = {'official': 'schedule314_official.json', 'personal': 'schedule314.json'}
    // http.get('schedule314_official.json').success(function(data){
    http.get(dict[scope.mode]).success(function(data){
        scope.days = data;
        scope.latex = "";
        var sday, lesson;
        for(var i = 0; i < scope.days.length; i++) {
            sday = scope.days[i];
            scope.latex += "    {\\begin{Large} " + sday.day + "  \\end{Large}  \n";
            scope.latex += "        \\begin{table}[!h]\n        \\begin{tabular}{ p{3cm}  p{10cm} p{5cm} }  \n";
            for(var j = 0; j < sday.lessons.length; j++) {
                lesson = sday.lessons[j];
                scope.latex += "            " + lesson.start + " - " + lesson.end + " & " + lesson.subj + " & " + lesson.place + "\\\\\n";
            }
            scope.latex += "        \\end{tabular}\n        \\end{table} \\\\\n";
        }
    });
}]);
index.html:

...
<ul class="nav nav-pills">
    <li role="presentation"><a href="#" ng-click="$parent.mode='official';">Official</a></li>
    <li role="presentation"><a href="#" ng-click="$parent.mode='personal';">Personal</a></li>
</ul>
...

你的问题是什么?你的脚本有效吗?@Blauharley上面的例子不起作用,问题是如何正确地在JSON文件之间切换。