barcharts 그리기에 대한 지시문을 쓰려고하는데 데이터가 변경 될 때마다 차트를 다시 그립니다. 내 컨트롤러에서 나는 어떻게, 그리고
/* This directive will create a bar chart based on a dataTable.
* It expects the first column of the data table to contain the labels.
* If more than 2 columns (labels plus more than one value) are supplied,
* all bars generated by values in one row will be grouped together, making
* an easy visual comparison (benchmark).
* If the option overlay is supplied, the odd value columns will be drawn
* underneath the even values (Ex [label, col1, col2, col3, col4], with overlay = true will result
* in col1 and col3 to be drawn underneath col2 and col4
*/
angular.module('kapstok').directive('nBarChart', ['$window', '$location', '$parse', '$timeout',
function($window, $location, $parse, $timeout){
return{
restrict: 'E',
scope: true,
link: function(scope, elm, attrs){
// Read all the different parameters givin in the directive declaration.
// If options are not given, they are replaced by their default values.
var dataGetter = $parse(attrs.data);
var data = dataGetter(scope) || undefined;
if(!data){
throw Error("No (valid) data source specified!");
}
// Redraw the table once the table gets updated. However, usually multiple elements
// of the table will be updated at the same time, while the watch will get triggered
// at each update. To prevent this, we give it a timeout of half a second,
// allowing all the updates to be applied before the table is redrawn.
scope.$watch(function(){ return data.getVersion(); }, $timeout(drawChart, 500));
: 아무것도 증가 '버전'라는 속성이 변경 될 때마다 데이터 테이블, 모든 기능에서
controlmodule.controller('PrefscanController',['$http', '$scope', 'DataTable', function($http, $scope, DataTable){
$scope.myData = new DataTable();
$scope.myData.addColumn("string", "label");
$scope.myData.addColumn("number", "survey");
$scope.myData.addColumn("number", "benchmark");
$scope.myData.addColumn("number", "break-it");
$scope.myData.addRow(['test', 20, 10, 4]);
$scope.myData.addRow(['test2', 42, 13, 2]);
$scope.hideBenchmark = function(){
console.log("myData.version = ", $scope.myData.getVersion());
$scope.myData.hideColumn(2);
console.log("myData.version = ", $scope.myData.getVersion());
}
가있는 무엇이다 나는 현재이가 나는 시계를보고 싶다.
내 템플릿에는 hideBenchmark 함수를 호출하는 ng-click 버튼이 있습니다. 이 함수가 호출되고 dataTable 버전이 업데이트되지만 시도 할 때마다 시계가 트리거되지 않습니다.
내 hideBenchmark 함수에서 $ scope. $ appy()/$ scope. $ digest()를 호출하여 시계에 'true'를 추가하고 (객체 불균형을 찾는) 'attrs.data ','data.version '과 그것의 아무도는 시계를 방아쇠를 당기는 것처럼 보이지 않는다! 나는이 데이터로부터 독립된 범위에서 또 다른 변수를 만들 수 있다는 것을 알고 있습니다. 데이터를 변경할 때마다 그것을 변경하고 변경합니다. 그러나 그것은 추악하고 불필요한 것처럼 보입니다.
시계가 작동하지 않는 이유를 아는 사람이 있습니까? 내가 원하는 것을 어떻게 할 수 있습니까?
감사합니다,
리누스
지시어의 범위에 특성을 가져 오는 대신 "데이터"를 넣으려고 했습니까? –