$范围。$ ...手表使其在另一个范围返回一个函数? [英] $scope.$watch ... make it return a function on another scope?

查看:122
本文介绍了$范围。$ ...手表使其在另一个范围返回一个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在Highcharts 2系列的数据返回值的监控功能。下面的例子说明如何做到这一点在控制器内工作:

I have a watch function that returns a value for 2 series of data in Highcharts. The example below shows how this would work within the controller:

$scope.$watch("trendCompany",function(){
   return $scope.chartConfig.series[0].data = 
            [-1.95,0.99,9.29,4.49,-1.50,-4.05,-7.05,10.13,-19.95,
            2.99,-14.55,-6.15,-20.25,-27.00,-26.10,-10.95,-10.95,5.30,
            6.06,11.12,10.13,11.96,22.13,6.74,4.67,1.43,0.27,4.20,-3.45,
            2.10,-1.65,1.92,1.85,0.00,1.97,-5.25,-3.30,1.67,3.87,6.27,1.89,
            2.27,0.59,-1.20,-5.85,-6.60,-2.25,-2.40,-2.85,-3.45,-0.15,2.63],
   $scope.chartConfig.series[1].data = 
            [1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2];
});

$scope.chartConfig = {
    options: {
        chart: {
            type: 'line'
        }
    },
    series: [{
        data: []
    },{
        data: []
    }],
    title: {
        text: 'Hello'
    },

    loading: false
}

我的问题是...怎么会
$ scope.chartConfig.series [Ⅰ]的.data等于另一函数,而不是这个静态数组?我有一个返回像这样的数据结果的函数:

My question is.. how would $scope.chartConfig.series[i].data be equal to another function rather than this static array? I have a function that returns a result of data like so:

//Let a propertyExpr string define a traversal route into an object
$scope.dataResult = function(obj, propertyExpr) {
  return $parse(propertyExpr)(obj);
}

我第一次尝试是去回看功能,做...

My first attempt was to go back to the watch function and do...

$scope.chartConfig.series[i].data = dataResult(obj, property);

然后,我试过...

Then, I tried...

$scope.chartConfig.series[i].data = function(){ return dataResult(obj,property); }

不过,这些都不是工作。我怎样才能使该系列产品范围相同的东西,通过函数调用的价值?

However, neither of these are working. How can I make the value of the series scope equal to something that is invoked by a function?

推荐答案

如果您在定义范围的功能,您还可以调用它这样。

If you define a function on the scope you also have to call it like that.

$scope.chartConfig.series[0].data = $scope.dataResult($scope.obj, $scope.property);

这篇关于$范围。$ ...手表使其在另一个范围返回一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆