Knockout JS + Bootstrap + Icons + html binding

核能气质少年 提交于 2019-12-05 11:02:39

Ok after several frustrating hours.....

it turns out, all I had to do was to pass $data to my computed observable in my template binding...

so, if we have the following view model:

function UserListViewModel()
{
  var self = this;
  self.ListItems = ko.observableArray([]);

  self.GetListItemText = ko.computedObservable(function(ListItem)
  {
    if(ListItem.isloginallowed == 1) {
      return '<i class="icon-user"></i> Disable User';
    }
    else {
      return '<i class="icon-user"></i> Enable User';
    }
  });
} 

Previously was causing me problems beacuse 'ListItem' as always null....

however, if I define my Binding as:

data-bind="html: GetListItemText($data)"

Magically when I then try to access my ListItem, I have my properties for each row I'm looping over :-)

Oh well, lessons to be learned....

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!