I want to bind the coordinate x ,y of rect.(Recorded as "Coordinate "). And drag the rect, hoping that the record (coordinate x ,y) will synchronous change.
Below are part of the code.(Complete code jsbin)
html
<tr ng-repeat="item in data">
<td>({{ item.x }}, {{ item.y }})</td>
<td>{{ item.width }}</td>
<td>{{ item.height }}</td>
</tr>
JS
$scope.data = [{ 'x': 30, 'y': 50, 'width': 90, 'height': 70 }];
var drag = d3.drag()
.on('drag', function (d) {
d3.select(this)
.attr('x', d.x = d3.event.x)
.attr('y', d.y = d3.event.y)
})
.on('end', function (d) {
//update coordinate x ,y to array
arrayNum = this.id;
$scope.data.splice(arrayNum, 1, { 'x': d.x, 'y': d.y, 'width': d.width, 'height': d.height });
console.log($scope.data);
});
I also have $scope.data.splice to update the array. And it really update the $scope.data. But it doesn't work on the browser view. How can I modify? Or what can I refer to? Thank's a lot!