:
<ol ui-selectable>
JS
var myApp = angular.module('soil', [])
myApp.directive('uiSelectable', function() {
return function (scope, el, attrs) {
el.selectable();
};
});
function ItemCtrl($scope) {
/* triggered by "ng-submit" on a form*/
$scope.addItem = function() {
/* newItem comes from "ng-model" on an input*/
if (!$scope.newItem.length) {
return;
}
$scope.items.push({
name: $scope.newItem
});
$scope.newItem = '';
};
$scope.newItem = '';
$scope.items = [{
name: 'one'
}, {
name: 'two'
}, {
name: 'three'
}];
}
DEMO : http://jsfiddle.net/2KzRt/5/
를
업데이트는 다음을 선택하면 목록 항목을 업데이트하는 모델의 AA 동적 집합을 만드는 방법은 다음과 같습니다
HTML :
<div id="update_items" ng-show="updateItems.length">
<div ng-repeat="item in updateItems">
<input value="{{item.name}}" ng-model="items[item.index].name"/>
</div>
<button ng-click="updateItems=[]">Cancel</button>
</div>
JS :
var myApp = angular.module('soil', [])
myApp.directive('uiSelectable', function() {
return function (scope, el, attrs) {
el.selectable({
stop:function(evt,ui){
var selected=el.find('.ui-selected').map(function(){
var idx=$(this).index();
return {name: scope.items[idx].name, index:idx}
}).get();
scope.updateItems=selected;
scope.$apply()
}
});
};
});
function ItemCtrl($scope) {
$scope.addItem = function() {
if (!$scope.newItem.length) {
return;
}
$scope.items.push({
name: $scope.newItem
});
$scope.newItem = '';
};
$scope.newItem = '';
$scope.updateItems=[];
$scope.items = [{
name: 'one'
}, {
name: 'two'
}, {
name: 'three'
}];
}
DEMO : http://jsfiddle.net/2KzRt/7/
감사에 대한 업데이트, 내 문제를 해결하는 것 같습니다. 귀하의 답변을 수락하기 전에 이해하지 못했던 것이 있는지 전체 신청서에 적용 해 보겠습니다. –
자신을 각성하는 학습 ... 이것은 역동적 인 모델을 만드는 법을 배우기에 좋은 운동이었습니다. 희망을 찾았습니다. – charlietfl
아주 잘 작동합니다. 나는 그것을 나의 필요에 조금 적용했고, 선택된 항목들의 새로운 이름을 묻기위한 대화 상자를 추가했다 : http://jsfiddle.net/SaBaJ/2/ –