我一直在尝试查找从重复生成的某个行的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 :(得分:0)
在您的控制器中,您可以参考rowId
和rowID
,它们是javascript中的两个不同变量。重命名它们以匹配。
在尝试刷新页面之前,您还应该等待帖子完成。通过.then()
$http.post
功能执行此操作
最后,我建议使用一些方法来改进此代码以获得最佳实践。你有什么应该使用上述修改,如果你正在学习,那就没问题。但是一旦你开始工作,我建议重构代码如下:
设置window.location是一种代码气味。我宁愿在这里看到代码重新下载数据而不刷新整个页面。
将$ http代码放入服务而不是控制器是最佳做法。