2016-02-19 60 views
0

我一直在試圖找到從重複產生一定行的ID或名稱找到一個特定的值。在這種情況下,我試圖發佈特定的行invoice_no。不幸的是我不確定我在這種情況下做了什麼。從納克重複的行

controller("myControllerMgmtVOM", ["myFactory", "$animate", "$timeout", "$q", "$http", "$filter", 
    function(myFactory, $animate, $timeout, $q, $http, $filter) { 
     var vm = this; 
     var setLoading = function(loading) { 
      vm.isLoading = loading; 
     }; 
     vm.count = function(idx) { 
      console.log(idx); 
     }; 
     setLoading(true); 
     $http.get("/index.php/Collections/getOpenAccountingAction/").then(function(res) { 
      vm.vom = []; 
      angular.forEach(res.data, function(val, idx) { 
       vm.vom.push({ 
        invcase_id: val.invcase_id, 
        invoice_no: val.invoice_no, 
        obj_id: val.obj_id, 
        contact: val.contact, 
        customer: val.cname, 
        open_date: val.fcdate, 
        followup_name: val.followup_name, 
        followup_date: val.fdatetime, 
        company_name: val.company_name, 
        notes: [] 
       }); 
      }); 
     }).then(function() { 
      angular.forEach(vm.vom, function(val, idx) { 
       $http.get("../Collections/getNote/?id=" + val.invcase_id).then(function(res) { 
        val.notes = []; 
        angular.forEach(res.data, function(note, idx) { 
         val.notes.push({ 
          detail: note.note_text, 
          date: note.createddate 
         }); 
        }); 
        var orderBy = $filter('orderBy'); 
        val.notes = orderBy(val.notes, '-date'); 
       }); 
       $http.get('/arinvoice/getamount?invoiceNo=' + val.invoice_no).then(function(response) { 
        vm.vom[idx].amount_due = '$ ' + response.data.Amount_Due; 
        vm.vom[idx].due_date = response.data.Due_Date; 
       }); 
      }); 
      setLoading(false); 
     }); 

     vm.hideRow = function(rowID) { 
     //var rowID = vm.vom.invoice_no; 
     $http.post("/index.php/Collections/closeAction/?id=" + rowID).then(function(res){ 
      window.location = "/index.php/Collections"; 
     }); 
    }; 
    } 
]); 

下面是前端:

<div class="marginBottom inline-flex"> 
    <md-button class="md-raised md-primary pad-10" href="" data-ng-click="clickSearch='1'">Search</md-button> 
</div> 
<div layout layout-sm="row" class="search-container pad-10 vanish" data-ng-show="clickSearch=='1'"> 
    <md-input-container flex> 
     <md-button class="md-primary md-raised pos-abs-right" data-ng-click="search=''">Clear</md-button> 
     <md-button class="md-primary md-raised pos-abs-right" data-ng-click="clickSearch=''">Close</md-button> 
     <label for="search">Keyword Search</label> 
     <input name="search" id="search" type="text" data-ng-model="search" /> 
    </md-input-container> 
</div> 
<div layout='row' class="stripeRow"> 
    <div flex class="pad-10 stripeTeal"> 
     <strong><a href="" data-ng-click="prop = 'open_date'; reverse=!reverse">Open Date</a></strong> 
    </div> 
    <div flex class="pad-10"> 
     <strong><a href="" data-ng-click="prop = 'invoice_no'; reverse=!reverse">Invoice Number</a></strong> 
    </div> 
    <div flex class="pad-10 stripeTeal"> 
     <strong><a href="" data-ng-click="prop = 'invcase_id'; reverse=!reverse">Invoice Case ID</a></strong> 
    </div> 
    <div flex class="pad-10"> 
     <strong><a href="" data-ng-click="prop = 'amount_due'; reverse=!reverse">Amount Due</a></strong> 
    </div> 
    <div flex class="pad-10 stripeTeal"> 
     <strong><a href="" data-ng-click="prop = 'due_date'; reverse=!reverse">Due Date</a></strong> 
    </div> 
    <div flex class="pad-10"> 
     <strong><a href="" data-ng-click="prop = 'customer'; reverse=!reverse">Customer/Company</a></strong> 
    </div> 
    <div flex class="pad-10 stripeTeal"> 
     <strong><a href="" data-ng-click="prop = 'contact'; reverse=!reverse">Customer Contact</a></strong> 
    </div> 
    <div flex class="pad-10"> 
     <strong><a href="" data-ng-click="prop = 'followup_name'; reverse=!reverse">Assigned To</a></strong> 
    </div> 
    <div flex class="pad-10 stripeTeal"> 
     <strong><a href="" data-ng-click="prop = 'followup_date'; reverse=!reverse">Next Follow-up Date</a></strong> 
    </div> 
    <div flex class="pad-10 "> 
     <strong><a href="" >Close</a></strong> 
    </div> 
</div> 
<md-list> 
    <md-item data-ng-repeat="row in vm.vom | orderBy:prop:reverse | filter:search" class="moving finish" data-ng-class-odd="'stripeGrey'" data-ng-class-even="'stripeWhite'" data-ng-init="visible=''"> 
     <md-item-content ng-show="row.amount_due!= '$ 0.00'" layout="row" class="vom"> 

      <div flex>{{::row.open_date}}</div> 
      <div flex>{{::row.invoice_no}}</div> 
      <div flex><a href="/index.php/Collections/edit/?id={{::row.invcase_id}}">{{::row.invcase_id}}</a></div> 
      <div flex>{{::row.amount_due}}</div> 
      <div flex>{{::row.due_date}}</div> 
      <div flex><a href="/index.php/Collections/cust_list/?id={{::row.obj_id}}">{{::row.customer}}</a></div> 
      <div flex>{{::row.contact}}</div> 
      <div flex>{{::row.followup_name}}</div> 
      <div flex> 
       {{::row.followup_date}} 
       <span class="float-r point vanish formContainer"> 
        <i class="fa fa-file-o" data-ng-mouseenter="visible=row[$index]"></i> 
        <div class="toolTip main-bg" data-ng-mouseleave="visible=''"> 
         <md-content class="md-padding vanish" data-ng-repeat="option in row.notes" data-ng-show="visible==row[$index]"> 
          <h5>{{option.date}}</h5> 
          <p>{{option.detail}}</p> 
         </md-content> 
        </div> 
       </span> 
      </div> 
       <div flex><md-button class="sm-raised sm-primary pad-10" href="" data-ng-click="vm.hideRow(row.invcase_id)">close</md-button></div> 

     </md-item-content> 
     <md-divider data-ng-if="!$last"></md-divider> 
    </md-item> 
</md-list> 

所以基本上我想要抓住的那行val.invoice_no價值和張貼。有人能解釋我可能改變什麼嗎?謝謝。

回答

0

在你的控制器,你是指rowIdrowID這是在JavaScript中兩個不同的變量。重命名它們以匹配。

你也應該等待您的文章在嘗試刷新頁面之前完成。通過在$http.post上使用.then()函數來實現此功能。最後,我會提出一些改進此代碼以獲得最佳實踐的方法。你有什麼應該與上述修改,並且如果你正在學習很好。但是,一旦你得到它的工作,我建議重構代碼如下:

設置window.location是一個代碼味道。我寧願在這裏看代碼,重新下載數據而不刷新整個頁面。

這是把你的$ HTTP代碼到一個服務,而不是控制最佳做法。

+0

哇,它始終是小事情。我已經調整了我的代碼以反映我的更改。謝謝。 – jcdevelopment