AngularJS和'控制器为'ui网格语法
AngularJS and 'Controller as' syntax with ui-grid
我在查找过滤器未定义的原因时遇到问题。。。
Uncaught ReferenceError:未定义筛选器(匿名函数)@mainController.js:46(匿名功能)@mainController.js:76
我错过了什么?
索引=
<!DOCTYPE html>
<html ng-app="app" ng-open="main.refreshData()">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="Content/site.css">
<!--<link data-require="ui-grid@*" data-semver="3.0.0RC18" rel="stylesheet" type="text/css" href="Content/ui-grid.css">-->
<link data-require="ui-grid@*" data-semver="3.0.0RC18" rel="stylesheet" href="http://ui-grid.info/release/ui-grid-unstable.css" />
<script src="Scripts/jquery-2.1.4.min.js"></script>
<script src="Scripts/angular.min.js"></script>
<script src="Application/app.module.js"></script>
<script src="Application/mainController.js"></script>
<script src="Scripts/ui-grid.min.js"></script>
</head>
<body ng-controller="MainController as main">
<input type="text" ng-model="main.food" placeholder="Enter food" />
<p>Sriracha sauce is great with {{main.food}}!</p>
<br />
<br />
<input type="text" ng-model="main.filterText" ng-change="refreshData()" placeholder="Search..." />
<br />
<br />
<h>{{main.title}}</h>
<div class="grid" ui-grid='main.gridOptions' id="grid1"></div>
</body>
</html>
app=
//The app.module.js file houses a single application-level module for your application.
//In this example, your application has an application-level module that loads the
//other modules of the application. The purpose of adding app.module.js as a separate
//file is to introduce the concept that modules, controllers, services, directives,
//views, etc. should be defined in their own files.
//<<Immediately-invoked function expression>>
//Immediately-invoked function expressions can be used to avoid variable hoisting from
//within blocks, protect against polluting the global environment and simultaneously
//allow public access to methods while retaining privacy for variables defined within the function.
(function () {
'use strict';
angular.module('app', []);
})();
控制器=
(function () {
'use strict';
angular
.module('app', ['ui.grid'])
.controller('MainController', main);
function main() {
var self = this;
self.food = 'pizza';
self.myData = [{
name: "Moroni",
age: 50
}, {
name: "Tiancum",
age: 43
}, {
name: "Jacob",
age: 27
}, {
name: "Nephi",
age: 29
}, {
name: "Enos",
age: 34
}];
self.gridOptions = {
data: "main.myData",
enableGridMenu: true
};
self.title = "ng-grid Example";
self.filterText;
self.refreshData = function () {
self.gridOptions.data = self.filter('filter')(self.myData, self.filterText, undefined);
};
}
//Define a custom filter to search only visible columns (used with grid 3)
filter('visibleColumns', function () {
return function (data, grid, query) {
matches = [];
//no filter defined so bail
if (query === undefined || query === '') {
return data;
}
query = query.toLowerCase();
//loop through data items and visible fields searching for match
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < grid.columnDefs.length; j++) {
var dataItem = data[i];
var fieldName = grid.columnDefs[j]['field'];
//as soon as search term is found, add to match and move to next dataItem
if (dataItem[fieldName].toString().toLowerCase().indexOf(query) > -1) {
matches.push(dataItem);
break;
}
}
}
return matches;
}
});
})();
将过滤器转换为函数并将其绑定到应用程序。
angular
.module('app', ['ui.grid'])
.controller('MainController', main)
.filter('visibleColumns', visibleColumns);
function visibleColumns () {...}
没有函数filter()
,有一个angular.module
对象的方法,称为filter('name', function() { ... })
。
有关自定义过滤器的更多信息
相关文章:
- ExtJS网格单元格编辑器,防止焦点松动问题
- ui网格将单元格显示为选择标记
- ui网格日期单元格过滤器,过滤日期格式导致显示错误的日期
- Extjs 4网格:根据存储文本值在单元格中放置图标
- ExtJ将工具提示添加到网格单元格文本中
- 编辑后更改切片网格单元格数据
- 如何使用 javascript 修改网格视图单元格值
- Syncfusion JavaScript 网格未显示.语法和引用错误
- Kendo UI网格有条件可编辑的单元格
- 用户输入的动态表,单元格id作为网格引用
- 在客户端的编辑模式下,在同一单元格网格视图中选中复选框时禁用文本框
- 剑道网格:在数据源同步后保留导航单元格
- 如何使用ng网格在单元格模板上应用字段
- Angularjs ng网格的选择单元格未选择正确的值
- KO网格无法保存编辑单元格中的数据-使用Plunker
- 剑道网格:如何在与Angular一起使用时从组合框单元格模板中获取所选项目
- C#网格视图从动态创建的DataTable中实现可点击单元格
- 在extjs网格4.0中获取textfield单元格td
- 剑道UI网格更新仅更改了单元格/列
- 如何在后台网格中将特定的可编辑单元格设置为不可编辑