I implement sort of FilePanels with folders and subfolders.
Visually from Chrome Developer Tools I can see that ui.item.sortable.droptarget
has data
attribute of parent-folder-id == 2
, but when I try to access it in code (via jquery data
method) it returns 10 (value of another folder's parent where I was recently).
Why it does not get updated? When I move to another folder - new value to vm.parentId
is assigned based on server's value of that folder. DOM is updated correctly...
<ul ui-sortable="vm.sortableOptions"
ng-model="vm.cache.items"
data-parent-folder-id="{{vm.parentId}}">
Added later:
Even if I update .data() getter to ui.item.sortable.droptarget.data("parentFolderId")
it still returns 10
Update 2: Added plunker demo: http://plnkr.co/edit/14XfBOTFuJZ0oSy2ozqh?p=preview
<html ng-app="plunker">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.6/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<div class="xxx" data-parent="{{parentId}}"></div>
<button ng-click="getParentId()">Get Parent Id</button>
<br>
<button ng-click="setParentId(15)">Set Parent Id to 15</button>
<br>
<button ng-click="getParentId()">Get Parent Id</button>
<br>
{{parentId}}
</body>
</html>
app.js
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, $element) {
activate();
function activate() {
$scope.parentId = 10;
}
$scope.setParentId = function(number) {
$scope.parentId = number;
}
$scope.getParentId = function() {
$scope.parentId = $($element).find('.xxx').data('parent');
}
});
When you click buttons in this sequence: Set - Get
- data
value succesfully updates. But when you click in another sequence: Get - Set - Get
- the same problem appears as in my previous code - after value was updated with new value when getting it - an old value returns.