- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
此代码使用 angularjs ng-table 模块在表格中显示值。
相关的html代码如下所示;
<div ng-controller="ViewCtrl" class="container">
<table ng-table="tableParams" class="table table-bordered">
<thead>
<tr>
<th>price_alert</th>
<th>lastPrice</th>
</tr>
<thead>
<tbody>
<tr ng-repeat="item in $data">
<td data-title="'price_alert'" ng-class="{ red: item.lastPrice < stk.price_alert }>
${{item.price_alert}}
</td>
<td data-title="'lastPrice'" ng-class="{ red: item.lastPrice < stk.price_alert }>
${{item.lastPrice}}
</td>
</tr>
</tbody>
</tbody>
</table>
</div>
CSS代码;
.red { color: red; }
Controller 代码;
controller('ViewCtrl', ['$scope', '$http', 'moment', 'ngTableParams',
function ($scope, $http, $timeout, $window, $configuration, $moment, ngTableParams) {
var tableData = [];
//Table configuration
$scope.tableParams = new ngTableParams({
page: 1,
count: 100
},{
total:tableData.length,
//Returns the data for rendering
getData : function($defer,params){
var url = 'http://127.0.0.1/list';
$http.get(url).then(function(response) {
tableData = response.data;
$defer.resolve(tableData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
params.total(tableData.length);
});
}
});
}])
在html代码中,重复了这个条件来显示文字颜色ng-class="{ red: item.lastPrice < stk.price_alert
.如果可能,如何修改代码以保持 DRY(不要重复自己)原则?
最佳答案
听起来您只想消除单个额外的“红色”类声明。为此,请像这样将您的 ng-class 放在 tr 中:
<tr ng-repeat="item in $data" ng-class="{ red: item.lastPrice < stk.price_alert }">
<td data-title="'price_alert'">
${{item.price_alert}}
</td>
<td data-title="'lastPrice'">
${{item.lastPrice}}
</td>
</tr>
然后将您的 css 更改为:
.red td { color: red; }
您不能使用此 css 在该行内嵌套额外的表格,但我猜您不需要这样做。
关于javascript - 此 html 代码的 DRY 一致性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33852207/
我是 DRY principle 的坚定拥护者: Every piece of knowledge must have a single, unambiguous, authoritative rep
假设我有一个稍微复杂的 for 循环,用于不同的情况。有没有一种方法可以提取该 forloop 并仍然保持代码可读性? 例如: private function bar(){ for(i=0;
JSData 是替代还是补充 Sequelize.js? 我试图了解这两个库如何一起玩以及是否应该一起玩。 从我的阅读来看,JSData 主要处理访问数据,而 Sequelize.js 将创建和修改
我有 aws-eks 集群,下面是我替换现有配置的命令。 kubectl create configmap flink-config --from-file=./config -o yaml --dr
我正在设计一个可重用的类库,其中包含 2 个名为 core.xml.dll 和 core.string.dll 的程序集(其中包括)。 xml 程序集引用字符串程序集,以便使用一些字符串辅助方法。 但
我正在尝试找到一种更 DRY 的方式来使用 docker-compose env。 docker-compose-base.yml base: image: reactjs_web v
我有一些看起来像这样的类(class): struct A { void *stuff; int x; int foo() const; } 我有一些采用这种类型参数的函数,例如 int
我目前正在 Silverlight 中构建一些自定义控件。我希望这些控件能够响应验证错误。我想要做的是在我的控件周围设置红色边框,就像默认的 Silverlight 控件一样。 我的理解是我需要将它添
我正在处理一些服务器端代码,在将它们传递给客户端之前包装所有异常,因此所有面向客户端的方法都有以下代码 try{ DoSomething(); } catch (ExceptionA e) {
“纵深防御”原则指出,应该在多个地方实现约束,这样如果一条数据绕过或漏过一层,就会在下一层被捕获。一个很好的例子是在网络应用程序中——你将验证放在客户端 javascript 中,放在服务器端代码中(
使用这种方法在 MVC 中查看模型:http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/06/29/how-we-do-mvc-view
我想将 jquery 脚本优化为多个元素(单个页面上有许多幻灯片)。我可以添加一些功能,但这并不干燥(不要重复自己)。 Pr
我有一些代码(不是我的),其中包含带有声明的范围映射的指令。我的愿望是在其他地方使用该指令并传递将在模板中使用的附加变量。 我要传递的变量是theVar。 我发现唯一可行的解决方案看起来很噩梦:
我将数据存储在数组中,并从该数组中使用循环创建表。对于一个表,我需要两列,另外 30 列(取决于数组项)。这将有三列。 var prodej = [ /*First column, second,
有没有更好的方法来声明来自同一组(例如“com.android.support”)具有相同版本(例如“23.4.0”)的多个软件包(例如“appcompat-v7”)? 实际申报: ... def a
我有一个看起来像这样的对象: var myObj = { _fooCon: function(f) { if (typeof f != 'function') throw
这就是我所拥有的。 Map data = new HashMap<>(); // assume this has been populated public int getLastestVersion
我在尝试维护 DRY 概念时遇到了 AngularJS 的问题 [不要重复自己]。我希望我做错了什么,有人可以指出我的错误。 一家公司销售卡车和汽车。 这两个项目具有相似和不同的属性。添加到其中一种的
我最终在几个类中得到了几个遵循相同模式的方法(每个类中总是有一堆这些方法): private void updateFoo() { String newFoo = fooTextField.g
假设我有一个字典config,其中包含键username和password。我想创建一个新字典,仅包含 config 中的username 和 password 键值对。一种方法是: new_dict
我是一名优秀的程序员,十分优秀!