[英]Accessing ng-init inside $scope from razor file Model
I am having trouble finding a way to get the index off of a property on a razor file. 我在寻找一种方法来获取剃刀文件上的属性的索引时遇到麻烦。 I need to match the index of the table to the array that I have on scope.
我需要将表的索引与作用域上的数组匹配。
I set a window value from my cshtml file to a scope property. 我将cshtml文件中的window值设置为scope属性。
scope.discountFlightList = dealViewModel;
dealViewModel contains an array of items.
dealViewModel包含一组项目。 Most importantly deal.Fare
最重要的是交易
I need to access a certain index of the array each time the button located on the razor file is clicked. 每次单击位于剃刀文件上的按钮时,我需要访问数组的某个索引。 Below is the button that I am working with.
下面是我正在使用的按钮。
<a href="" ng-click="openPriceChart()" class="btn-primary btn-sm pull-right hide-on-mobile"><span ng-bind-html="@deal.Fare | roundPrice | superCurrency: '@Language.Currency' : true"></span>* <i class="ha-icon fontIcon-angle-right"></i></a>
The index that I need is based on the fare value that I can see on ng-init which exists on each td of
我需要的指数是基于票价价值,我可以在其上存在的每个TD NG-INIT见
<td ng-init="myInit('@deal.OriginText')"> // in dev tools = San Francisco, California
Ideally I would know what the index is when I click on the a href and set it to the array index.
理想情况下,当我单击a href并将其设置为数组索引时,我会知道索引是什么。 I was hoping this answer would do it How can I pass @Model to Angular ng-init
我希望这个答案会做到这一点如何将@Model传递给Angular ng-init
var testValue
$scope.myInit = function(name){
testValue = name;
} }
But I am getting an empty string when I check on my debugger. 但是当我检查调试器时,我得到一个空字符串。
Since the razor file is using a foreach as opposed to the ng-repeat I don't see how I can use $index. 由于剃刀文件使用的是foreach而不是ng-repeat,所以我看不到如何使用$ index。
@foreach (var deal in @Model.Deals.Take(Model.NumberOfFaresToDisplay ?? 6))
{
Any help would be greatly appreciated. 任何帮助将不胜感激。
Your answer is here: Getting index value on razor foreach 您的答案在这里: 获取razor foreach的索引值
@{int i = 0;}
@foreach(var myItem in Model.Members)
{
<span>@i</span>
i++;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.