【问题标题】:How to update Model value when trigger controller function?触发控制器功能时如何更新模型值?
【发布时间】:2015-09-22 07:29:22
【问题描述】:

控制器:

onSelectRow : 
       function(id){ 
            setTimeout(function () {$scope.getSelectedRow(); }, 0);
          },};

$scope.getSelectedRow = function(){

var grid = $("#patientgrid");

var rowKey = grid.jqGrid('getGridParam',"selrow");

var kelr = grid.jqGrid('getCell', rowKey, 'PostTopic');

if (rowKey)
{ 
     $scope.lastsel=kelr;   
}
else
alert("No rows are selected");}

HTML:

 <h1>Topic:{{lastsel}}</h1>

问题是... 当我选择新行时,“lastsel”不会改变。

【问题讨论】:

    标签: javascript jquery angularjs jqgrid


    【解决方案1】:

    我使用 $apply 并且它有效!

    $scope.getSelectedRow = function(){

            var grid = $("#patientgrid");
            var rowKey = grid.jqGrid('getGridParam',"selrow");
            var kelr = grid.jqGrid('getCell', rowKey, 'PostTopic');
            if (rowKey)
            {
                $scope.lastsel; 
                $scope.$apply(function() 
                {
                    $scope.lastsel=kelr;
                },1);  
    
               }
            else alert("No rows are selected");
        }
    

    【讨论】:

      猜你喜欢
      • 2021-12-27
      • 2015-11-25
      • 2020-01-09
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多