简体   繁体   English

可以在控制台中看到JSON数据,无法呈现到浏览器

[英]Can see JSON data in console, can't render to browser

I'm pulling JSON data from a local file. 我正在从本地文件中提取JSON数据。 If the data is true then I want to append it to a div, if not then it shouldn't appear at all. 如果数据为true那么我想将其附加到div上,如果不是,那么它根本就不会出现。

I can see the true data in console.log so now it's a matter of appending it, but I'm running into an issue with my return statement (see code below). 我可以在console.log看到true数据,因此现在只需添加它即可,但是我的return语句遇到了问题(请参见下面的代码)。 Any thoughts? 有什么想法吗?

JS snippet: JS代码段:

import testjson from './test.json';

    function loadTopCourses() {
        let isTop = testjson.d.results.filter(x => x.TopTrainingCourse === true) {
            return {
                "Title": val.Title
            }
        };

        console.log(isTop)

        let showTopTitles = isTop;

        for (var i = 0; i < showTopTitles.length; i++) {
            let li = $("<li></li>");
            $(li).append(showTopTitles[i].Title);
            $(".top-training-ul").append(li)
        };

    } // ------------------ loadTopCourses

    loadTopCourses();

JSON snippet: JSON代码段:

{
   "d": {
     "results": [
       {
         ...
         "Id": 1,
         "Title": "Training 1",
         "Category": "Enter Choice #1",
         "Topic": "Enter Choice #1",
         "Description": "My Test description",
         "TopTrainingCourse": false, // ------------ //
         "ID": 1,
         "Modified": "2019-03-05T20:13:46Z",
         "Created": "2019-03-05T20:13:36Z"
       },
...
...
"FileSystemObjectType": 0,
         "Id": 2,
         "Title": "Training 2",
         "Category": "Enter Choice #2",
         "Topic": "Enter Choice #1",
         "Description": null,
         "TopTrainingCourse": true, // ------------- //
         "ID": 2,
         "Modified": "2019-03-05T20:14:00Z",
         "Created": "2019-03-05T20:13:53Z"
       },
...
...

console.log: 的console.log:

(7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}] // ------ correct # of true values
0: {__metadata: {…}, FirstUniqueAncestorSecurableObject: {…}, RoleAssignments: {…}, AttachmentFiles: {…}, ContentType: {…}, …}
1:
ID: 4
Id: 4
Modified: "2019-03-05T22:33:04Z"
OData__UIVersionString: "1.0"
ParentList: {__deferred: {…}}
RoleAssignments: {__deferred: {…}}
Title: "Training 4"
TopTrainingCourse: true // ------------- //
Topic: "Enter Choice #1"

You can map the filtered results into a new array of the form that you want: 您可以将过滤后的结果map到所需表单的新数组中:

let isTop = testjson.d.results.filter(x => x.TopTrainingCourse === true)
.map(x => { return { Title: x.Title } });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在浏览器控制台中看不到 react lint 错误 - I can't see react lint errors in my browser console 无法在控制台上获取 JSON 数据 - Can't get JSON data on console 无法在* ngFor中呈现数据,但已在控制台中以角度7显示 - can't render the Data in *ngFor but it already show in console in angular 7 无法从Fetch response.json()返回JSON字段(但可以从console.log中看到它) - Can't return JSON field from Fetch response.json() (but can see it from console.log) 推入数组控制台日志可以看到,但不会在HTML中呈现为什么? angularJS - push into an array console log can see but won't render in html why? angularJS PDF在FF浏览器窗口中时看不到Acrobat JS控制台 - Can't see Acrobat JS console when PDF is in an FF browser window Codeigniter / JSON / AJAX-无法从URL查看数组数据 - Codeigniter/JSON/AJAX - Can't see array data from URL 数据来自父组件,我们也可以在控制台中看到,但它不会在子组件中呈现相同的数据。 它也没有显示任何东西 - Data is coming from parent component also we can see in console, but it is not render same data in child. also it is not displaying anything 即使在控制台上也无法从 json 获取数据 - can't get data from json even getting a response on the console JavaScript控制台可以看到对象的内容,但是我无法访问它 - JavaScript console can see contents of Object but I can't access it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM