List.js示例不起作用

时间:2017-04-15 21:50:16

标签: javascript html list list.js

我正在尝试复制List.js页面上的示例,以创建新列表。我复制并粘贴了示例中的代码,但是我在.js库文件上收到错误。

以下是代码:

HTML:

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputDatesList = new ArrayList<>();
        System.out.print("Available booking dates (DD-MM-YYYY): ");
        while(!in.lines().allMatch(input -> input.matches("(0?[1-9]|[12][0-9]|3[01])-(0?[1-9]|1[012])-((20)(17|18))"))){
            System.out.println("The date format is not correct (DD-MM-YYYY).");
            in = new BufferedReader(new InputStreamReader(System.in));
        }
        inputDatesList.addAll(in.lines().collect(toList()));

JS:

<!DOCTYPE html>
<html>
<head>
<script src="http://listjs.com/assets/javascripts/list.min.js"></script>
<meta charset=utf-8 />
<title>Existing list</title>

<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="script.js"></script>

</head>
<body>
  <div id="users">
  <input class="search" placeholder="Search" />
  <button class="sort" data-sort="name">
    Sort by name
  </button>

  <ul class="list"></ul>

</div>
</body>
</html>

这是我得到的错误:

var options = {
  valueNames: [ 'name', 'born' ],
  item: '<li><h3 class="name"></h3><p class="born"></p></li>'
};

var values = [{
    name: 'Jonny Strömberg',
    born: 1986
  },
  {
    name: 'Jonas Arnklint',
    born: 1985
  },
  {
    name: 'Martina Elm',
    born: 1986
}];

var userList = new List('users', options, values);

userList.add({
  name: "Gustaf Lindqvist",
  born: 1983
});

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

System.ObjectDisposedException
var options = {
  valueNames: [ 'name', 'born' ],
  item: '<li><h3 class="name"></h3><p class="born"></p></li>'
};

var values = [{
    name: 'Jonny Strömberg',
    born: 1986
  },
  {
    name: 'Jonas Arnklint',
    born: 1985
  },
  {
    name: 'Martina Elm',
    born: 1986
}];

var userList = new List('users', options, values);

userList.add({
  name: "Gustaf Lindqvist",
  born: 1983
});