【发布时间】:2014-02-20 11:46:09
【问题描述】:
我分阶段设置了我的 .Net MVC 解决方案,并确保 Angular JS 和 KendoUI 都能独立工作。
app.js:
var app = angular.module("app", ['kendo.directives']);
在我的控制器中,我定义了以下内容:
app.controller('contentTypesController', ['$scope', '$log', 'contentTypesRepository',
function ($scope, $log, contentTypesRepository) {
var a = {};
$scope.status;
$scope.contentTypes;
$scope.contentTypeOptions;
// for testing purposes, but not used - used for navigation properties
$scope.users;
getContentTypes();
function getContentTypes() {
// call the data repository
contentTypesRepository.getList()
.success(function (contentTypes) {
//console.log(contentTypes.value[0].Description);
//$log.log(contentTypes.value[0].Description)
$scope.contentTypes = contentTypes;
$scope.contentTypeOptions = {
dataSource: {
data: contentTypes
},
dataTextField: "Description",
dataValueField: "ContentTypeId",
optionLabel: "Select a Content Type"
};
})
.error(function (error) {
$scope.status = 'Unable to load data: ' + error.message;
});
}
$scope.updateContentTypes = function (id) {
var contentType;
for (var i = 0; i < $scope.contentTypes.length; i++) {
var currentType = $scope.contentTypes[i];
if (currentType.ID === id) {
contentType = currentType;
break;
}
}
};
$scope.insertContentType = function () {
// get contentType description from the client
var contentType = { 'Description': $scope.newContentType };
contentTypesRepository.insert(contentType)
.success(function () {
$scope.status = 'Added new content type. Refreshing list.';
// add the new content type to the client-side collection
$scope.contentTypes.value.push(
{ 'Description': $scope.newContentType }
);
$scope.newContentType = "";
})
.error(function (error) {
$scope.status = 'Unable to insert new content type: ' + error.message;
});
};
$scope.deleteContentType = function(id) {
contentTypesRepository.remove(id)
.success(function () {
$scope.status = 'Deleted content type. Refreshing list.';
for (var i = 0; i < $scope.contentTypes.length; i++) {
var contentType = $scope.contentTypes[i];
if (contentType.ID === id) {
// remove the content type from the client-side collection
$scope.contentTypes.splice(i, 1);
break;
}
}
// navigation properties = null
// $scope.xxxx = null;
})
.error(function (error) {
$scope.status = 'Unable to delete content type: ' + error.message;
});
};
// get some navigation property
//$scope.getCustomerOrders = function (id) {
// dataFactory.getOrders(id)
// .success(function (orders) {
// $scope.status = 'Retrieved orders!';
// $scope.orders = orders;
// })
// .error(function (error) {
// $scope.status = 'Error retrieving customers! ' + error.message;
// });
//};
$scope.addContentType = function () {
//return $scope.newContentType.$save();
$scope.contentTypes.value.push(
{ 'Description': $scope.newContentType }
);
$scope.newContentType = "";
}
按照 Angluar/Kendo 示例 here,我添加了与 $scope.contentTypeOptions 相关的代码。
在我看来:
<select kendo-drop-down-list k-options="contentTypeOptions"></select>
显示下拉列表,但没有数据。
我可以查看ng-repeater 中的数据:
<ul>
<li ng-repeat="contentType in contentTypes.value">
{{ contentType.Description }}
</li>
</ul>
以及{{ contentTypeOptions }} 的原始数据。
由于中继器使用 contentTypes.value,我也尝试过
$scope.contentTypeOptions = {
dataSource: {
data: contentTypes.value // tried both contentTypes and contentTypes.value
},
dataTextField: "Description",
dataValueField: "ContentTypeId",
optionLabel: "Select a Content Type"
};
...基于 JSON 数据:
最终,我希望将所有 CRUD 连接到一个网格(我过去使用 OData 完成,但现在将 AngularJS 添加到混合中)并认为只需在 Angular/Kendo 混合中显示数据即可是一个好的开始。我希望在解决这个问题后,剩下的会很简单,并感谢任何建议。
【问题讨论】:
-
我会在 github angular-kendo repo 中问这个问题,但即便如此,kendo ui 似乎也没有太多关注该项目。我已经成功地连接了一个相当不错的剑道网格和多选设置与角度,但没有任何其他剑道小部件。
-
contentTypes.value的类型是什么?
-
@LarsHöppner -
value是一个包含内容类型对象的集合/数组。
标签: javascript asp.net-mvc angularjs kendo-ui odata