2016-01-12 30 views
0

我正在使用angularjs和xeditablejs在表格上顯示下拉菜單(同時添加新行)。現在,選擇一個下拉菜單後 - 我想爲該行自動填充下一列。但是,ng-change或ng-click不會觸發對我的控制器的函數調用。無法通過點擊或更改下拉菜單調用函數(angularjs,xeditablejs)

HTML片段:

<div ng-if="pcMasterData" class="ng-cloak"> 
     <b>ProfitCenter Table</b> 
     <br /> 
     <table class="table table-bordered table-hover table-condensed" style="width: 40%"> 
      <tr style="font-weight: bold"> 
       <td>ProfitCenter Id</td> 
       <td>ProfitCenter Description</td> 
      </tr> 
      <tr ng-repeat="row in pcMasterData"> 
       <td> 
        <span editable-select="row.ProfitCenterId" e-name="pcid" e-form="rowform" e-required e-ng-options="pcInfo.ProfitCenterId as pcInfo.ProfitCenterId for pcInfo in pcInfoArray" ng-model="kkPcId" ng-change="setPcDescription(kkPcId)"> 
         {{row.ProfitCenterId}} 
        </span> 
       </td> 
       <td> 
        <span e-name="pcdescription" e-form="rowform"> 
         {{row.ProfitCenterDescription || pcDescription}} 
        </span> 
       </td> 
      </tr> 

JS片段:

 $scope.setPcDescription = function (pcId) { 
     alert("[here-" + pcId + "]"); 
     // filter data from infoArray 
     $scope.pcDescription = getDescriptionFromArray(pcId, infoArray); 
    }; 

這裏,setPcDescription()是沒有得到所謂的一切!

==========================================

更新1: 我用e-ng-change =「setPcDescription($ data)」代替,現在調用這個函數。這裏的$ data是pcId。所以,我必須使用infoArray來查找描述。但是,它解決了我的問題。

回答

0

由於您處於ng-repeat塊中,因此您處於由ng-repeat創建的範圍內,該範圍沒有您正在查找的setPcDescription。

您可以使用$ parent.setPcDescription(),但不建議這樣做,因爲您必須跟蹤函數上方的引用範圍。

如果您使用controllerAs語法,(Awesome article by Todd Motto),您將能夠更輕鬆,一致地引用控制器功能。