Angularjs 角度ui网格没有行
我的页面上有一个有角度的网格。它显示数据的唯一时间是我在gridOptions中设置数据,而不是http成功回调。代码如下:Angularjs 角度ui网格没有行,angularjs,angular-ui-grid,Angularjs,Angular Ui Grid,我的页面上有一个有角度的网格。它显示数据的唯一时间是我在gridOptions中设置数据,而不是http成功回调。代码如下: $scope.gridOptions = { showfooter: false, enablePaging: true, paginationPageSizes: [15], paginationPageSize: 50, enableRowSelection: false,
$scope.gridOptions = {
showfooter: false,
enablePaging: true,
paginationPageSizes: [15],
paginationPageSize: 50,
enableRowSelection: false,
primaryKey: 'Id',
multiSelect: false,
enableSorting: false,
enableVerticalScrollbar: true,
enableHorizontalScrollbar: true,
groupable: false,
rowHeight: 75,
columnDefs:
[
{
field: 'Id', visible:false
},
{
field: 'Name'
},
{
field: 'CategoryName',
DisplayName: 'Category'
},
{
field: 'Actions',
DisplayName: 'Actions',
cellTemplate: '<a href="#" title="Edit" ng-click="goToEditInst(row)"><span class="glyphicon glyphicon-edit"></span></a>'
}
]
};
$scope.searchInstituions = function () {
var formObj = $scope.searchForm;
var svc = formObj.service;
var city = formObj.city;
var cat = formObj.category;
var params = { CategoryId: ((cat == null)?-1:cat.Id) , ServiceId: ((svc == null) ? -1 : svc.Id), Cityid: ((city == null) ? -1 : city.Id) };
$http({
method: 'POST',
url: '/getjson',
data: $.param(params),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
})
.success(function (data, status, headers, config) {
data = [{ "Id": 1, "Name": "Golden Hills School District No. 75", "CategoryName": "Schools" }];
$scope.gridOptions.data = data;
})
.error(function (data, status, headers, config) {
alert('Error: ' + status + ". " + data);
});
};
$scope.gridOptions={
showfooter:false,
enablePaging:true,
分页页面大小:[15],
分页页面大小:50,
enableRowSelection:false,
primaryKey:'Id',
多选:错,
启用排序:false,
enableVerticalScrollbar:true,
enableHorizontalScrollbar:true,
分组:false,
行高:75,
columnDefs:
[
{
字段:“Id”,可见:false
},
{
字段:“名称”
},
{
字段:“CategoryName”,
DisplayName:“类别”
},
{
字段:“操作”,
DisplayName:“操作”,
单元格模板:“”
}
]
};
$scope.searchInstitutions=函数(){
var formObj=$scope.searchForm;
var svc=formObj.service;
var city=formObj.city;
var cat=formObj.category;
var params={CategoryId:((cat==null)?-1:cat.Id),ServiceId:((svc==null)?-1:svc.Id),Cityid:((city==null)?-1:city.Id)};
$http({
方法:“POST”,
url:“/getjson”,
数据:$.param(params),
标题:{'Content Type':'application/x-www-form-urlencoded'}
})
.success(函数(数据、状态、标题、配置){
数据=[{“Id”:1,“名称”:“金山学区第75号”,“类别名称”:“学校”}];
$scope.gridOptions.data=数据;
})
.error(函数(数据、状态、标题、配置){
警报('错误:'+状态+“+数据);
});
};
注意,我将数据硬编码为一个元素的数组
这方面的html是:
<fieldset ng-controller="InstitutionController">
<legend>Search Results:</legend>
<div class="gridStyle" ui-grid="gridOptions"></div>
</fieldset>
搜索结果:
在.success回调上设置$scope.gridOptions.data时,网格不显示任何行。(它是为那些将询问是否调用该函数的人而调用的
但我是否在网格选项中设置了它,如下面所示,它显示得很好:
$scope.gridOptions = {
data: [{ "Id": 1, "Name": "Golden Hills School District No. 75", "CategoryName": "Schools" }],
showfooter: false,
enablePaging: true,
paginationPageSizes: [15],
paginationPageSize: 50,
enableRowSelection: false,
primaryKey: 'Id',
multiSelect: false,
enableSorting: false,
enableVerticalScrollbar: true,
enableHorizontalScrollbar: true,
groupable: false,
rowHeight: 75,
columnDefs:
[
{
field: 'Id', visible:false
},
{
field: 'Name'
},
{
field: 'CategoryName',
DisplayName: 'Category'
},
{
field: 'Actions',
DisplayName: 'Actions',
cellTemplate: '<a href="#" title="Edit" ng-click="goToEditInst(row)"><span class="glyphicon glyphicon-edit"></span></a>'
}
]
};
$scope.gridOptions={
数据:[{“Id”:1,“名称”:“金山学区第75号”,“类别名称”:“学校”}],
showfooter:false,
enablePaging:true,
分页页面大小:[15],
分页页面大小:50,
enableRowSelection:false,
primaryKey:'Id',
多选:错,
启用排序:false,
enableVerticalScrollbar:true,
enableHorizontalScrollbar:true,
分组:false,
行高:75,
columnDefs:
[
{
字段:“Id”,可见:false
},
{
字段:“名称”
},
{
字段:“CategoryName”,
DisplayName:“类别”
},
{
字段:“操作”,
DisplayName:“操作”,
单元格模板:“”
}
]
};
我错过了什么!!!修复了它
问题出现在以下HTML中:
<form ng-submit="searchInstituions()" ng-controller="InstitutionController">
....
</form>
<fieldset ng-controller="InstitutionController">
<legend>Search Results:</legend>
<div class="gridStyle" ui-grid="gridOptions"></div>
</fieldset>
....
搜索结果:
请注意,有两个元素form和fieldset,属性为ng controller。我猜$scope对于这两个元素是不一样的。
一旦我将上述内容更改为以下内容,它就开始正常工作。经验教训:
<form ng-submit="searchInstituions()" ng-controller="InstitutionController">
...
<div class="clear" style="margin-top: 50px;"></div>
<fieldset>
<legend>Search Results:</legend>
<div class="gridStyle" ui-grid="gridOptions"></div>
</fieldset>
</form>
...
搜索结果:
谢谢你的帮助你使用的是哪个版本的ui网格。这个例子做了完全相同的事情,它工作ui网格-v3.0.0-RC.18-d9b2314-2015-01-06我检查了这个例子。这个例子在前面已经工作了。我有另一个网格做了完全相同的事情,它也工作了。我不知道为什么这个是不吉利的。我检查了拼写,什么都没有oes不会给出任何错误,但不会显示任何行。如果您的问题没有正确的html,其他人将很难理解这一点。我同意。对此表示抱歉。我没有想到这一点