Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

javascript - Change the cells of a table in an interval time using OData model

I have this code and I need my table to show the first 10 patients and, after 10 seconds, show the next 10 without touching any button (automatically).

I'm looking for something similar to this: https://embed.plnkr.co/ioh85m5OtPmcvPHyl3Bg/

But with an OData model (as specified on my view and controller).

This is my view:

<Table id="tablaPacientes" items="{/EspCoSet}">
  <columns>
    <!-- ... -->
  </columns>
  <ColumnListItem>
    <ObjectIdentifier title="{Bett}" />
    <!-- ... -->
  </ColumnListItem>
</Table>

This is my controller:

onInit: function () {
  var oModel = this.getOwnerComponent().getModel("zctv");
  this.getView().setModel(oModel);
},

onBeforeRendering: function () { // method to get the local IP because I need it for the OData
  var ipAddress;
  var RTCPeerConnection = window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
  var self = this;

  function grepSDP (sdp) {
    var ip = /(192.168.(0|d{0,3}).(0|d{0,3}))/i;
    sdp.split('
').forEach(function (line) {
      if (line.match(ip)) {
        ipAddress = line.match(ip)[0];
        self.setIp(ipAddress);
      }
    });
  }

  if (RTCPeerConnection) {
    (function () {
      var rtc = new RTCPeerConnection({
        iceServers: []
      });
      rtc.createDataChannel('', {
        reliable: false
      });
      rtc.onicecandidate = function (evt) {
        if (evt.candidate) {
          grepSDP(evt.candidate.candidate);
        }
      };
      rtc.createOffer(function (offerDesc) {
        rtc.setLocalDescription(offerDesc);
      }, function (e) {
        console.log("Failed to get Ip address");
      });
    })();
  }
},

setIp: function (ip) {
  this.getView().byId("planta").bindElement({
    path: "/CenTVSet('" + ip + "')"
  });
  var oModel = this.getView().getModel();
  var that = this;
  oModel.read("/CenTVSet('" + ip + "')", {
    success: function (oData, oRes) {
      var einri = oData.Einri;
      var orgpf = oData.Orgpf;
      var oTable = that.getView().byId("tablaPacientes");
      var oBinding = oTable.getBinding("items");
      var aFilters = [];
      var filterO = new Filter("Orgna", sap.ui.model.FilterOperator.EQ, orgpf);
      aFilters.push(filterO);
      var filterE = new Filter("Einri", sap.ui.model.FilterOperator.EQ, einri);
      aFilters.push(filterE);
      oBinding.filter(aFilters);
    }
  });
}

I searched some functions like IntervalTrigger but I really don't know how can I use it for this example.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. You could bind you items using bindItems, pass skip,top parameters and wrap the whole thing in a setInterval
var iSkip = 0;
var iTop = 10;
setInterval(function() {

    table.bindItems("/EspCoSet", {
        urlParameters: {
            "$skip": iSkip.toString() // Get first 10 entries
            "$top": iTop.toString()
        },
        success: fuction (oData) {
            iSkip = iTop; // Update iSkip and iTop to get the next set
            iTop+= 10;
        }
        ...
    }, 10000); // Each 10 seconds
)

  1. Almost the same thing, just use oModel.read to read the entities into you viewModel.allEntities, bind your table to the viewModel.shownEntities and use a setInterval to get the next 10 from allEntities to update shownEntities.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...