TVJS TVML 切换按钮

TVJS TVML toggle button

我有一个按钮,我希望能够单击该按钮并将图像更改为其他内容,听起来很简单。

 <buttonLockup toggle="true">
        <badge src="resource://button-rate-off" class="whiteButton" />
        <title>Add to Favourites</title>
      </buttonLockup>

应更改为:

 <buttonLockup toggle="true">
        <badge src="resource://button-rate-on" class="redButton" />
        <title>Remove from Favourites</title>
      </buttonLockup>

在我的 Presenter.js 中,我有一个加载函数可以检测我是否选择了项目:

load: function(event) {
    console.log(event);

    var self = this;
    var ele = event.target;
    var toggle = ele.getAttribute("toggle");

    if (toggle)
    {
           console.log(ele);
           var badge = ele.getElementsByTagName("badge").item(0);
           console.log(badge);
           badge.src = "resource://button-rated"; // Doesn't change
    }
},

关于如何改变它有什么想法吗?

好的,这似乎可行,但我遇到了上面部分的奇怪重新布局问题:

var isTrueSet = (toggle === 'true');
        var badge = ele.getElementsByTagName("badge").item(0);
        if (isTrueSet == true)
        {
            badge.setAttribute('src', 'resource://button-rated'); 
        } else {
            badge.setAttribute('src', 'resource://button-rate');
        }
        ele.setAttribute('toggle', !isTrueSet);