数据没有保存在变量中?

时间:2016-01-20 15:31:39

标签: angularjs

我有这段代码

$scope.setContent = function (data) {
        if ($scope.unfiltered_tree == null) {
            $scope.unfiltered_tree = data;
        }
   }

第一次保存在unfiltered_tree中的数据,当新数据出现时,它没有保存。

对此有何帮助?

1 个答案:

答案 0 :(得分:0)

我不完全理解你的问题。您是否在询问如何将新数据存储在变量中?只需删除if语句。

$scope.setContent = function (data) {
        $scope.unfiltered_tree = data;
   }

if语句的目的可能是检查您的变量是否已初始化。在这种情况下,您可能需要使用以下格式:

$scope.setContent = function (data) {
        if (!$scope.unfiltered_tree) {
            // Variable has not been initialized yet
            $scope.unfiltered_tree = data;
        } else {
            // Variable has been initialized before, do something else
          }
   }