0

I want to apply backcolor from dynamically using knockout.js Viewmodel.

Like In HTML

<table border="1"  > // I need back color over here
    <tbody>
        <tr>
            <td>
…………

My 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);
                                   }
                                 }
            });
   }

I need to set color code on table which is in the departcompetencebackcolor property .

Pragnesh Khalas
  • 2,908
  • 2
  • 13
  • 26
  • possible duplicate of [How to use knockout.js with ASP.NET MVC ViewModels?](http://stackoverflow.com/questions/11055336/how-to-use-knockout-js-with-asp-net-mvc-viewmodels) – Ryan Jan 17 '15 at 09:31

1 Answers1

0

You can try using style binding. You can check how to use it here http://knockoutjs.com/documentation/style-binding.html

In your case the table definition should look like this:

<table border="1" data-bind="style: { backgroundColor : departcompetencebackcolor() }">
ssimeonov
  • 1,416
  • 12
  • 13