我有类似于以下工作代码
<section class="row-fluid result" ng-repeat="result in getResults()">
<p>{{result.name}}</p>
<p>{{result.link}}</p>
</section>
结果
有另一个名为resultId的属性
其中 result.resultId
将返回以下源前缀之一:一、二、三。
例如,这些是典型的 resultId:One3244243、One23036043、Two3890234、Three23114232
而前缀的含义是:
One=Source ABC
Two=Source XYZ
Three=Source WXY
所以,现在我还想根据结果的 id 显示每个结果的来源 前缀:
<section class="row-fluid result" ng-repeat="result in getResults()">
<p>{{result.name}}</p>
<p>{{result.link}}</p>
<p><!-- display 'Source ABC' if result.resultId starts with One --> </p>
<p><!-- display 'Source XYZ' if result.resultId starts with Two--> </p>
<p><!-- display 'Source WXY' if result.resultId starts with Three --> </p>
</section>
最佳答案
执行 ng-show="result.resultId.indexOf('One') == 0"
等
关于javascript - 是否有用于 angularJS 的 String.startsWith(String),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21084573/