我正在使用数据表显示数据。当我单击一行时,我要处理数据,然后进行数据绑定以显示这些数据。这是我为datatable事件准备的代码:

table.on( 'select', function ( e, dt, type, indexes ) {
            $scope.siege = {
                economique: 30,
                affaire: 30,
                premiere: 30
            };

            if ( type === 'row' ) {
                var avion = table.rows( indexes ).data()[0];

                $scope.getConfiguration(avion);

                // do something with the ID of the selected items
            }
        } );


如您所见,对于该示例,我想将数据绑定到$ scope.siege,但是它不起作用,并且控制台中没有任何提示。

但是,如果我放:

$scope.siege = {
    economique: 30,
    affaire: 30,
    premiere: 30
};


在控制器中的其他地方它可以工作。

谢谢您的帮助。

最佳答案

尝试放置一个$ scope。$ apply ..,因为它让angular知道您需要刷新$ scope(如果您不在angular事件中)..像这样:

table.on( 'select', function ( e, dt, type, indexes ) {
            $scope.siege = {
                economique: 30,
                affaire: 30,
                premiere: 30
            };

            if ( type === 'row' ) {
$cope.$apply(function(){
   var avion = table.rows( indexes ).data()[0];

                $scope.getConfiguration(avion);

                // do something with the ID of the selected items
})

            }
        } );

07-26 05:47
查看更多