无法重置angular.js

时间:2016-04-14 13:02:54

标签: javascript angularjs

我有两个单选按钮,其中NO是deault。一旦用户点击YES选项,我将保存此值并尝试将YES设置为选中的单选按钮。但是一旦用户更改其选项,我就无法编辑默认值。这是我的代码:

    <body ng-app="mainModule" class="">
<div ng-controller="AdminConfigController">
    <div class="aui-page-panel aui-page-focused aui-page-focused-small" id = "continueDiscovery">
        <div class ="aui-page-panel-inner">
            <section class="aui-page-panel-content" >
                <label>Use User Story template while creating JIRA issue for Product features?</label>
                <div ng-repeat="eval in getEvaluators()">
                    <label class="radio" >
                        <input type="radio" ng-model="cell.evaluator" ng-click ="setConfig(cell.evaluator)" name="evaluatorOptions" value="\{{eval.name}}">\{{eval.name}}
                    </label>
                </div>
                <hr />
                <div>You picked: \{{cell.evaluator}}</div>
            </section>
        </div>
    </div>
</div>
</body>

控制器代码:

angular.module('mainModule').controller('AdminConfigController', function($scope, $http){


    $scope.cell = function() {
        return $http.get('/getAdminConfig/').success(function(data){
            template = data[0].userTemplate;

        }).error(function(data){
            console.log('Error: ' + data)
        });
    };

    $scope.cell = {
        evaluator: "NO"
    };

    $scope.updateCell = function (option) {
        $scope.cell = {
            evaluator: option
        };

        console.log($scope.cell)
    }
    $scope.evaluators = [{
        name: "YES"
    }, {
        name: "NO"
    }];
    $scope.getEvaluators = function () {
        return $scope.evaluators;
    };

    $scope.setConfig = function (option) {
        console.log("Config Choice:" + option)

        updateCell(option)

        $scope.option = option
        console.log("Entry Choice"+ $scope.option)

        var data = {
            userTemplate : $scope.option
        }

        $http.delete('/resetConfig/').success(function(data){

        }).error(function(data){
            console.log('Error: ' + data)
        });

        $http.post('/setAdminConfig/' , data).success(function(data){
            console.log(data)
            /*$scope.productDiscoveryData = data;*/
        }).error(function(data){
            console.log('Error: ' + data)
        });

    };
});

因此,如果您查看控制器代码,我需要更改默认值

$scope.cell = {
            evaluator: "NO"
        };

到用户选择的选项。

1 个答案:

答案 0 :(得分:0)

我希望这段代码可以帮到你。

    @api.multi
    def _calculate_geom(self):
        for record in self:
            if record.cor != False:
                self.env.cr.execute('SELECT ST_Transform(ST_GeomFromText(\'MULTIPOLYGON((('+str(record.cor).encode('utf-8')+')))\',4326),900913)')
                record.cor2=record.env.cr.fetchone()[0]
                if record.cor2 != False:
                    self.env.cr.execute('UPDATE '+self._name.replace('.', '_')+' set the_geom=\''+record.cor2+'\'')
M-x edebug-defun