下面是我用来格式化数字并将其重新分配回文本字段的代码。在删除文本时,我遇到了一些问题,完整的文本被删除而不是逐个字符,而且我无法重新输入文本。请指导我解决这个问题。
(function () {
'use strict';
angular
.module('orders')
.config(routeConfig);
routeConfig.$inject = ['$stateProvider'];
function routeConfig($stateProvider) {
$stateProvider
.state('orders', {
abstract: true,
url: '/orders',
template: '<ui-view/>'
})
.state('orders.list', {
url: '',
templateUrl: 'modules/orders/client/views/list-orders.client.view.html',
controller: 'OrdersListController',
controllerAs: 'vm',
resolve: {
orderResolve: getOrders
},
data: {
pageTitle: 'Orders List'
}
})
.state('orders.create', {
url: '/create',
templateUrl: 'modules/orders/client/views/form-order.client.view.html',
controller: 'OrdersController',
controllerAs: 'vm',
resolve: {
orderResolve: newOrder
},
data: {
pageTitle: 'Orders Create'
}
})
.state('orders.edit', {
url: '/:orderId/edit',
templateUrl: 'modules/orders/client/views/form-order.client.view.html',
controller: 'OrdersController',
controllerAs: 'vm',
resolve: {
orderResolve: getOrder
},
data: {
pageTitle: 'Edit Order {{ orderResolve.name }}'
}
})
.state('orders.view', {
url: '/:orderId',
templateUrl: 'modules/orders/client/views/view-order.client.view.html',
controller: 'OrdersController',
controllerAs: 'vm',
resolve: {
orderResolve: getOrder
},
data: {
pageTitle: 'Order Details {{ orderResolve.name }}'
}
});
}
getOrder.$inject = ['$stateParams', 'OrdersService'];
function getOrder($stateParams, OrdersService) {
return OrdersService.get({orderId: $stateParams.orderId}).$promise;
}
newOrder.$inject = ['OrdersService'];
function newOrder(OrdersService) {
return new OrdersService();
}
}());
答案 0 :(得分:0)
我运行了你的代码并没有遇到这些问题。如果您使用的是XIB或Storyboard,请仔细检查“编辑开始时清除”未选中“
另外,我需要设置变量才能使其工作:
var maxCharactersLimit = 10
和textField(_ textField:UITextField,shouldChangeCharactersIn范围:NSRange,replacementString string:String)
let finalTextCount = textField.text?.characters.count != nil ? textField.text!.characters.count : 0