将jquery数组转换为vue数组

时间:2017-06-28 13:31:08

标签: jquery vue.js

我有一个jquery函数,可以将表行转换为数组。

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\aa82758>cd C:\Users\aa82758\Desktop\build\exe.win-amd64-3.6

C:\Users\aa82758\Desktop\build\exe.win-amd64-3.6>vsc.exe
Traceback (most recent call last):
  File "C:\Users\aa82758\Anaconda3\lib\site-packages\cx_Freeze\initscripts\__sta
rtup__.py", line 14, in run
    module.run()
  File "C:\Users\aa82758\Anaconda3\lib\site-packages\cx_Freeze\initscripts\Conso
le.py", line 26, in run
    exec(code, m.__dict__)
  File "vsc.py", line 2, in <module>
  File "C:\Users\aa82758\Anaconda3\lib\site-packages\numpy\__init__.py", line 14
2, in <module>
    from . import add_newdocs
  File "C:\Users\aa82758\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line
 13, in <module>
    from numpy.lib import add_newdoc
  File "C:\Users\aa82758\Anaconda3\lib\site-packages\numpy\lib\__init__.py", lin
e 8, in <module>
    from .type_check import *
  File "C:\Users\aa82758\Anaconda3\lib\site-packages\numpy\lib\type_check.py", l
ine 11, in <module>
    import numpy.core.numeric as _nx
  File "C:\Users\aa82758\Anaconda3\lib\site-packages\numpy\core\__init__.py", li
ne 36, in <module>
    from . import numeric
  File "C:\Users\aa82758\Anaconda3\lib\site-packages\numpy\core\numeric.py", lin
e 1842, in <module>
    from .arrayprint import array2string, get_printoptions, set_printoptions
  File "C:\Users\aa82758\Anaconda3\lib\site-packages\numpy\core\arrayprint.py",
line 24, in <module>
    from .fromnumeric import ravel
  File "C:\Users\aa82758\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py",
 line 15, in <module>
    from . import _methods
ImportError: cannot import name '_methods'

C:\Users\aa82758\Desktop\build\exe.win-amd64-3.6>

我想将jquery数组转换为以这种方式构造的vue数组。

 $("#table1 tr").click(function () {
                // alert($(this).text());
                //  alert($(this).children("td").html());
                // app.greet();
                var $row = $(this).closest("tr"),       // Finds the closest row <tr> 
                    $tds = $row.find("td");             // Finds all children <td> elements

                $.each($tds, function () {               // Visits every single <td> element
                    // console.log($(this).text());
                    list.push($tds);
                    // Prints out the text within the <td>
                });
                console.log(list.length)
            });

这是我尝试这样做的方式,但是我得到意外结束的json输入错误。

 data() {
        return {
            tableRow: [
                {
                    "name": "name1",
                    "numSongs": "joker",
                    "Year": "year"
                }
            ]
        }
    },

有没有人有任何建议。

1 个答案:

答案 0 :(得分:1)

Json.Parse将字符串转换为对象,因此您无法使用它,请尝试:

       $("#table1 tr").click(function () {
            var list = [];

            var $row = $(this).closest("tr"),    
                $tds = $row.find("td");     

            list.push({name:$tds.eq(0).text(), numSongs:$tds.eq(1).text(), Year:$tds.eq(2).text()});
        });

您可以更改$tds.eq(index).text()以检索单元格值。