如何在Bonita的自定义小部件中定义angular js过滤器

时间:2018-12-13 17:22:46

标签: angularjs bonita

我在BONITA UI设计器中使用Angular Js创建了一个简单的自定义小部件。 我在控制器内部定义了应用程序控制器 我不确定该部分及其在BONITA中的工作方式 我也添加了所有资产。

   app.filter('startFrom', function() {
   return function(input, start) {
   start = +start;
   return input.slice(start);}})

var startFrom= $filter('filter');
startFrom([],  function(input, start) {
if (input) {
start = +start;
return input.slice(start);}
return [];});

但是,它似乎无法正常工作。

我想知道是否错过了一部分。 任何帮助表示赞赏。

先谢谢了。 模板代码是

 <input ng-model="q" id="search" class="form-control" placeholder="Filter text">
 <ul>
<li ng-repeat="item in data | filter:q |startFrom:currentPage*pageSize | 
limitTo:pageSize">    
    <div>{{item.firstname}}</div>
   </li></ul>
  <button ng-disabled="currentPage == 0" ng-click="currentPage=currentPage-1">Previous </button>  {{currentPage+1}}/{{numberOfPages()}}  <button ng-disabled="currentPage >= getData().length/pageSize - 1" ng- 
     click="currentPage=currentPage+1">  Next </button>`

控制器是

   function sds($scope, $filter) {
    var ctrl = this;

    $scope.startFrom=0;
    $scope.currentPage = 0;
    $scope.pageSize = 10;
    $scope.data =  [
  {
   "firstname": "Studio", 
   "userName": "studio"  
   },
  {
   "firstname": "Giovanna", 
   "userName": "giovanna.almeida"  
  },
  {
   "firstname": "Daniela",
   "userName": "daniela.angelo"
  },
  {
   "firstname": "Walter",
    "userName": "walter.bates"
  },
 {
   "firstname": "Giovanna", 
   "userName": "giovanna.almeida"  
  },
  {
   "firstname": "Daniela",
   "userName": "daniela.angelo"
 },
 {
   "firstname": "user1",
    "userName": "user1.name"
 },
 {
  "firstname": "user2",
  "userName": "user1.name"
 },
 {
  "firstname": "user3",
   "userName": "user1.name"
 },
 {
   "firstname": "user4",
    "userName": "user1.name"
 }

 ];

    $scope.q = '';

    $scope.getData = function () {
  return $filter('filter')($scope.data, $scope.q)
}

$scope.numberOfPages=function(){
    return Math.ceil($scope.getData().length/$scope.pageSize);
}

for (var i=0; i<65; i++) {
   // $scope.data.push("Item "+i);
}

$scope.$watch('q', function(newValue,oldValue){                      
    if(oldValue!=newValue){
    $scope.currentPage = 0;
  }
}

  var startFrom= $filter('filter');

  startFrom([],  function(input, start) {
        if (input) {
    start = +start;
   return input.slice(start);
   }
   return [];
   }
 ); 


 /*
app.filter('startFrom', function() {
return function(input, start) {
start = +start;
return input.slice(start);
}})
*/

}

0 个答案:

没有答案