此应用程序使用存储过程,角度js以及jquery。 基本上我想让我的类别名称显示在我的HTML中。目前我只能显示类别ID。我正在使用存储过程。
所以我有一个类别表和一个事务表。我的交易表有一个类别ID。我的类别表有一个名称。 Transactions Table Categories Table
HTML:
<tbody>
<tr class="even pointer" ng-repeat="transaction in dashboard.transactions">
<td class=" a-center ">
<input type="checkbox" class="tableflat">
</td>
<td style=" color:green">{{transaction.Description}}</td>
<td class=" ">{{transaction.Amount}}</td>
<td class=" "> {{transaction.CategoryId}}</td>
<td class=" ">{{transaction.Date}}</td>
<td class=" ">{{transaction.Status}}</td>
<td class=" last">
<button data-hover="tooltip" title="Edit" style="height:25px; width:35px" class="fa fa-pencil" ng-click="dashboard.getTransaction1(transaction.Id)" data-toggle="modal" data-target=".eTrans-modal-sm"></button>
<button data-hover="tooltip" title="Delete" style="height:25px; width:35px" class="fa fa-trash" ng-click="dashboard.deleteTransaction(transaction.Id)"> </button> <!--data-toggle="modal" data-target=".dTrans-modal-sm">-->
</td>
</tr>
</tbody>
分类模型:
c.cmodel = {
Id: '',
HouseholdId: '',
Name: '',
ExpenseTF: ''
};
交易模型:
t.tmodel = {
Id: '',
Name: '',
Amount: '',
RecAmount: '',
AccountId: '',
CategoryId: '',
Date: '',
Description: '',
Status: ''
};
从数据库获取事务的存储过程。在我声明一个新的varible来保存CategoryName之后,我认为这是我可以进行某种连接的地方。我想我还需要在事务模型中添加一个新变量(比如CategoryName),这样我就可以在HTML中查看它了。我只是不确定如何完成这个。
ALTER PROCEDURE [dbo].[GetTransactionByAccount]
-- Add the parameters for the stored procedure here
@accountId int
AS BEGIN
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT * from Transactions where AccountId = @accountId
END
如何在HTML中显示要显示的类别名称而不是类别ID。请注意,事务中存在Ng-Repeat。当页面加载时会引入转移。
答案 0 :(得分:0)
SELECT trx.*, cat.Name as CategoryName from Transactions trx
inner join Category cat
on cat.Id = trx.CategoryId
where AccountId = @accountId
然后在您的HTML中,您可以
<td class=" "> {{transaction.CategoryName}}</td>