我使用了syncfusion网格,我想从API将数据绑定到syncfusion网格 但绑定到syncfusion网格的数据不起作用
这里是网格的
的HTml代码<div ng-controller="ContactsController as contact">
<div id="Grid" ej-grid e-datasource="contact.Cdata" e-columns="contact.columns" e-toolbarsettings='contact.tools' e-toolbarclick="contact.toolbarHandler"
e-editsettings="contact.edittsetings" e-allowsorting="contact.allowsorting" e-sortsettings="contact.sortsettings" e-actionbegin="contact.actionBegin" e-allowpaging="contact.allowpaging"
e-pagesettings="contact.pagesettings" e-editsettings="contact.editsettings" e-allowreordering="contact.allowReordering" e-allowresizing="contact.allowResizing">
</div>
</div>
这是Controller方法::
function ContactsController(CommonService) {
this.Cdata = [];
var d = CommonService.getCantactList();
d.then(function (response) {
ContactsController.prototype.Cdata = response.data.Items;;
console.log("success");
}, function (error) {
console.log("error");
});
}
并且commonService是
this.getCantactList = function () {
return $http.get("http://localhost:63138/api/Contact/GetContactsbyClientId?clientId=1", { cache: true });
}
API方法是::
public object GetContactsbyClientId(int clientId)
{
try
{
//return (ContactService.GetListByClientId(clientId));
return new { Items = ContactService.GetListByClientId(clientId) };
}
catch (Exception)
{
throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
{
Content = new StringContent("An error occurred, please try again or contact the administrator."),
ReasonPhrase = "Critical Exception"
});
}
}
答案 0 :(得分:0)
问题可能是由于以下行。
ContactsController.prototype.Cdata = response.data.Items;;
应该如下。
function ContactsController(CommonService) {
this.Cdata = [];
proxy = this;
var d = CommonService.getCantactList();
d.then(function (response) {
proxy.Cdata = response.data.Items;
console.log("success");
}, function (error) {
console.log("error");
});
现在它将按预期工作。