将无效值传递给数据变量

抱歉我的英语不好,嗨,我是 Vue 的初学者,我有 iussue,无法解决。我从 API 加载有关艺术的数据(只是一个字典列表),然后我制作多数组(列表列表),当我保存原始 response.data 时,我的多数组在 vue 实例的数据变量中我得到了类似的数据,但我不更改源列表:


http://img1.mukewang.com/62d952ea0001429303100333.jpghttp://img2.mukewang.com/62d952f00001133602880306.jpg

在原始变量字段中 offsetX 和 offsetY 不得存在。场高也被打破了。那些字段也传入原始变量,我不知道为什么。我的应用程序代码:


$(document).ready(function () {


    var app = new Vue({

        el: '#app',

        data: {

            raw: null,

            info: null,

            art_width: 252,

            window_width: null,

            window_height: null,

        },

        mounted() {

            this.window_width = window.innerWidth

            this.window_height = window.innerHeight 

            axios({

                method: 'get',

                url: '/content/art',

                contentType: 'application/json'

            })

            .then(function (response) {

                app.raw = response.data.items.slice();

                // If i delete create_array from app, raw variable is normal

                app.info = create_array(app.raw)

            });

            window.addEventListener('resize', () => {

                if (app.raw !== null){

                    app.info = create_array(app.raw)

                    this.window_width = window.innerWidth

                    this.window_height = window.innerHeight 

                }

            });

        },

        computed: {

            arts_in_line () {

                return parseInt((this.window_width - 24*2) / (this.art_width+10));

            },

            center_div_width ()  {

                return this.arts_in_line * (this.art_width + 10)

            }

        }

    })


});



function create_array(info) {

    // Gets number of arts in line

    arts_in_line = parseInt((window.innerWidth - 24*2) / (252+10));

    // For return 

    var multi_array = [];

    // Create mulri array

    for (var index = 0; index < info.length; index = index + arts_in_line) {

        multi_array.push(info.slice(index, index+arts_in_line));

    }

   

PIPIONE
浏览 79回答 1
1回答

饮歌长啸

而不是做// Create mulri array&nbsp; &nbsp; for (var index = 0; index < info.length; index = index + arts_in_line) {&nbsp; &nbsp; &nbsp; &nbsp; multi_array.push(info.slice(index, index+arts_in_line));&nbsp; &nbsp; }您可以简单地创建一个新数组multi_array并循环info添加您想要的内容multi_array。例如&nbsp; &nbsp; var multi_array = [];&nbsp; &nbsp; // Save vertical offsets&nbsp; &nbsp; var top_offset = []&nbsp; &nbsp; for (var row = 0; row < info.length; row ++) {&nbsp; &nbsp; &nbsp; &nbsp; for (var col = 0; col < info[row].length; col ++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;let scale = 252 / parseInt(info[row][col]['width']);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const temp = {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id: info[row][col]['id'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Additional values you want&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: (parseInt(multi_array[row][col]['height']) * scale) + 'px'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;multi_array[row][col] = temp&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; return multi_array;这样,您可以在新数组中添加和排除您想要的任何键。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript