我想使用knockout.js Viewmodel动态应用backcolor。
与HTML相似
<table border="1" > // I need back color over here
<tbody>
<tr>
<td>
…………
我的ViewModel
function SelfEmpPerformance() {
var that = this;
that.departcompetencebackcolor = ko.observable('');
$.ajax({
type: "GET",
cache: false,
url: baseUrl() + "/EmpSelfReview/GetSelfReviewData",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
if (data.Success == 1) {
that.departcompetencebackcolor(data.SelfEmpPerformance.
departcompetencebackcolor);
}
}
});
}
我需要在offcompetencebackcolor属性中的表上设置颜色代码。
答案 0 :(得分:0)
您可以尝试使用样式绑定。您可以在http://knockoutjs.com/documentation/style-binding.html
查看如何使用它在您的情况下,表定义应如下所示:
<table border="1" data-bind="style: { backgroundColor : departcompetencebackcolor() }">