2016-08-02 63 views
0

我是SAPUI5的新手。我有两个控制器participantList.controller.js和Topic.controller.js。我已经在participantList.js中定义了名为refreshData的函数,我试图调用该函数Topic.Controller.js。总体而言,我在ParticipantList视图中设置了顶级进度指标。因此,每次当我从主题视图导航到参与者视图时,通过选择主题视图上的主题,我想重新启动参与者视图上的进度指示器。请帮忙!在SAPUI5中按下重新启动进度指示器按钮选择?

这里是ParticipantList.controller.js代码:

var reset; 
var list; 

sap.ui.define([ 
    "fiveminuteapp/controller/BaseController", 
    "fiveminuteapp/controller/Topic.controller" 
], 

function(BaseController, participant) { 
    "use strict"; 


    return BaseController.extend("fiveminuteapp.controller.participant.ParticipantList", { 

     onInit: function() { 

      var topicheader = this.byId("employeeListPage"); 
      topicheader.setTitle(topic); 

      this.listfunction(); 
      this.testFunction();    
     }, 

     refreshData: function() { 
      clearInterval(reset); 
      lTime.setText("5:00"); 
      setInterval(reset); 

     },   

     testFunction: function() { 
      var setMinutes = 5; 
      var originalTime = setMinutes * 60; 
      var time = originalTime; 
      var lTime = this.byId("labelTimeLeft"); 
      var progress = this.byId("progressIndicator"); 

      reset = setInterval(function() { 
       var minutes; 
       var seconds; 

       if (time > -1) { 
        minutes = Math.floor(time/60); 
        seconds = time % 60; 
        time = time - 1; 

        if (minutes < 10 && seconds < 10) { 
         lTime.setText("0" + minutes + ":" + "0" + seconds); 
        } else if (minutes < 10) { 
         lTime.setText("0" + minutes + ":" + seconds); 
        } else if (seconds < 10) { 
         lTime.setText(minutes + ":" + "0" + seconds); 
        } 
        progress.setPercentValue((time/originalTime) * 100); 

       } else { 
        clearInterval(reset); 
        lTime.setText("5:00"); 
        setInterval(reset); 
        if(lTime.getText() === "00:00"){ 
         $.ajax({ 
          type: "post", 
          data:{username: username}, 
          url:"/fiveminuteapp/AddPoints" 
         }) 

        } 
       } 
      }, 1000); 
     }, 

     listfunction: function(){ 
      var test = this.getView().byId("participantList"); 
      setInterval(function(){ 
       var aData = $.ajax({ 
        type: "get", 
        data:{topic : topic}, 
        contentType : "application/json", 
        url:"/fiveminuteapp/RetrieveName", 
        dataType: "json", 
        async:false, 
       }).responseJSON; 

       var oModel = new sap.ui.model.json.JSONModel(aData); 
       test.setModel(oModel, 'listmodel') 

      },5000) 
     } 
    }); 
}); 

这里是Topic.Controller.js代码:

sap.ui.define([ 
    "fiveminuteapp/controller/BaseController", 
    "fiveminuteapp/controller/participant/ParticipantList.controller" 
], function(BaseController, participant) { 
    "use strict"; 

    return BaseController.extend("fiveminuteapp.controller.Topic", { 
     onNavToParticipant: function(oEvent) { 
      var otime = window.originalTime; 
      var oItem = oEvent.getSource(); 
      var oContext = oItem.getBindingContext("topics"); 
      var topicSelected = oContext.getProperty("TopicChoices"); 

      topic = topicSelected; 

      $.ajax({ 
       type: "post", 
       data:{username: username, topic : topic}, 
       url:"/fiveminuteapp/InsertTopic" 
      }) 


      this.getRouter().navTo("participantList"); 
      var time = participant.refreshData(); 
      //sap.ui.controller("ParticipantList.controller.js").refreshData(); 
     } 
    }); 
}); 

Topic view

Participant view

回答

0

我假定您在应用程序中使用路由。如果是,则可以将路由模式匹配处理程序附加到特定路由,每次匹配特定路由时,框架将调用哪些处理程序。

ParticipantList.controller.js onInit()方法注册一个处理程序:

oRouter.getRoute("participantList").attachPatternMatched(this._onRouteMatched, this); 

然后用名_onRouteMatched()实现ParticipantList.controller.js处理函数本身:

_onRouteMatched: function (oEvent) { 
    this.refreshData(); 
} 

更多细节可以发现in the official UI5 documentation

相关问题