我正在构建一个地址簿,用户可以在点击它们时编辑字段。我通过一个帖子找到了这个小提琴: http://jsfiddle.net/timriley/GVCP2/
但它没有解释如何使用JSON样式数据源。作为Angularjs的初学者,我很难找到一种方法将可编辑的表单绑定到数据模型,所以我的尝试很差:
function ClickToEditCtrl($scope) {
$scope.contacts = [
{
"id": 1,
"Name": "Betty",
"Surname": "Smith",
"Address": "24 Funny Avenue, wc149m, London, United Kingdom"
},
{
"id": 2,
"Name": "Anabella",
"Surname": "Vicks",
"Address": "19 Euston Road n12clm, London, Isle of Man"
}];
$scope.editorEnabled = false;
$scope.enableEditor = function() {
$scope.editorEnabled = true;
$scope.editableAddress = $scope.contacts.Address;
};
$scope.disableEditor = function() {
$scope.editorEnabled = false;
};
$scope.save = function() {
$scope.contacts = $scope.editableAddress;
$scope.disableEditor();
};
}
如何在JSON数组中使所有字段都可编辑和可更新?
答案 0 :(得分:0)
忘记上面的混乱问题。我发现这个很棒的AngularJS Bundle我希望我在2天前知道:http://vitalets.github.io/angular-xeditable/。
固定