代码之家  ›  专栏  ›  技术社区  ›  bafix2203

无引用标记的角度更新ng模型

  •  0
  • bafix2203  · 技术社区  · 8 年前

    这是我的代码: JS:

     $scope.gamma = {
            0 : 2
        };
        $scope.matrix = {
            1 : 21, 2 : 25, 3 : 21, 4 : 85, 5 : 798, 6 : 4, 7 : 51, 8 : 224, 9 : 63
        };
        $scope.update_layers = function(gamma, gvalue, matrix, mvalue){
    
            $scope.gamma = gamma;
             if(gvalue){
                    $scope.gamma.gvalue = parseInt(gvalue)
    
                    for(var i in $scope.gamma){
                $scope.gamma[i] = parseInt($scope.gamma[i]);
            }
            }
    
            if(mvalue){
                    $scope.matrix.mvalue = parseInt(mvalue)
            }
    

    HTML:

    {{gamma}}{{matrix}}
                        <br />
                   gamma : <span ng-repeat="(g, value) in gamma"> <input class="form-control" style="margin:5px;width:100px;text-align:center;display:inline-block;text-align:center"  ng-model="gamma[g]"></span>
                            <br />
                   matrix : <span ng-repeat="(m, value) in matrix"> <input class="form-control" style="margin:5px;width:100px;text-align:center;display:inline-block;text-align:center"  ng-model="matrix[m]"></span>
    
    
                        <button class="btn" ng-click="update_layers(gamma, gamma.value, matrix, matrix.value)">update</button>
    

    我想展示: "1":21 而不是 "1":"21" 在这里,我的PLNKR和我的Effors: http://plnkr.co/edit/LFvqgeCtOWv4OGxiDDuY?p=preview

    1 回复  |  直到 8 年前
        1
  •  1
  •   Aleksey Solovey    8 年前

    type="number"

    <input type="number" class="form-control" style="margin:5px;width:100px;text-align:center;display:inline-block;text-align:center" ng-model="matrix[m]">
    
    推荐文章