Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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
Sorting 使用下划线排序的Vue.js排序_Sorting_Underscore.js_Vue Component_Vuejs2 - Fatal编程技术网

Sorting 使用下划线排序的Vue.js排序

Sorting 使用下划线排序的Vue.js排序,sorting,underscore.js,vue-component,vuejs2,Sorting,Underscore.js,Vue Component,Vuejs2,正在尝试在Vue组件上实现sortBy方法。这是我到目前为止所拥有的 var studentTableComp = { template: '#studentTable', data: function () { return { students: data, show: true, columns: [ 'id', 'can

正在尝试在Vue组件上实现sortBy方法。这是我到目前为止所拥有的

var studentTableComp =  {
    template: '#studentTable',
    data: function () {
        return {
            students: data,
            show: true,
            columns: [
                'id',
                'candidateType',
                'complete'
            ]
        }
    },
    methods: {
        sortBy: function (sortKey, e) {
            e.preventDefault();
            _.sortBy(this.students.students, sortKey);
        }
    },
}
我可以看到sortBy函数正在被命中,并且参数sortKey正在从模板中正确发送,但是问题似乎出在
\上。sortBy
函数对
this.students.students
数组没有任何影响

知道它为什么不起作用了吗。

我使用下划线示例数组尝试了
.sortBy
方法,效果很好,但我认为当数组添加到Vue组件上的数据时,可能会发生一些情况,从而阻止此函数正常工作。

我看到
.sortBy
工作,请参阅fiddle

代码如下:

var demo = new Vue({
    el: '#demo',
    data: function(){
        return {
        students: [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}]
      };
    },
    methods: {
      sorted: function() {
        return _.sortBy(this.students, 'name');
      }
    }
})

如果您发现此问题仍未解决,请从回购协议中添加更多代码。

谢谢-但上面的代码似乎与我使用的代码完全相同,只有一个例外。我的排序数据位于Vue组件上,而不是Vue对象本身。我原以为这可能与数据数组有关,但我给了组件上面的数组,并在u.sortBy函数前后检查了数组,但数组没有变化