变量(搜索)未定义错误

时间:2016-06-02 04:52:26

标签: javascript jquery json sorting

function sort(type) {
    $("#parentDiv").empty();
    $.getJSON("raw_data.json", ({ Search }));

    function Sear(a, b) {
        return (a[Search.type] < b[Search.type]) ? -1 : (a[Search.type] > b[Search.type]) ? 1 : 0;
    };
}

我的raw_data.json将是here

虽然我已宣布搜索。它出现了一个错误:

  

未定义搜索。

1 个答案:

答案 0 :(得分:0)

function sort(type) {
  $("#parentDiv").empty();
$.getJSON("raw_data.json", ({ Search }) => {   
    Search.sort(function(a,b){
    if(a[type]<b[type]){return -1;}
     else if(a[type]>b[type]){
    return 1;
    }
    else {
    return 0;
    }
    });
    console.log(`Sorted by: ${type}`);
    console.log("movies are displayed!!");
    var i;
   ... code