如何使playerinitemptyseats上卸下使用的座椅?
假设seatid为1,那么它将从seat: 1中删除​​emptyseats吗?

   vm.emptyseats = [
      {seat: 1},
      {seat: 2},
      {seat: 3},
      {seat: 4},
      {seat: 5},
      {seat: 6},
      {seat: 7},
      {seat: 8},
      {seat: 9},
    ];


    vm.playerinit = function(x) {
      console.log("init user data");
      var seatid = x.position;

      // vm.emptyseats remove where seat: seatid

    };

最佳答案

使用本机Array#filter函数:

vm.playerinit = function(x) {
      console.log("init user data");
      var seatid = x.position;

      // vm.emptyseats remove where seat: seatid
      //Using ES6 arrow function syntax
      vm.emptyseats = vm.emptyseats.filter( (empty_seat) => empty_seat.seat !== seatid);
      //Or regular syntax
      vm.emptyseats = vm.emptyseats.filter( function(empty_seat) {     return empty_seat.seat !== seatid});

    };

10-08 04:57