淘汰赛自定义绑定没有解雇更新

时间:2016-06-08 07:41:17

标签: javascript knockout.js

是的另一个问题。不幸的是,这些其他答案都没有帮助: Knockout custom binding not updating

Possible to fire custom binding update except initially?

Knockout custom binding for bootstrap select not updating viewmodel "selectedCategories/selectedCategory"

Update is not called in knockout.js custom binding

Custom Binding not working updating from Knockout 2.3 to 3.3

Knockout, noUiSlider, custom bindings

Knockout custom binding update function not firing

尝试了所有这些并且更新仍未解雇!!!

由于html绑定不被接受为虚拟biding,我正在尝试创建自己的,因为我的情况下的模板不起作用!

foreach中的html:

...
<!-- ko ifnot: $parent.raceData.sufficientFPS -->
    <!-- ko fktml: resultItem.html --><!-- /ko -->
<!-- /ko -->
...

javascript:

...
this.html = ko.observable('<td>1</td><td>Lastname</td><td>something 1</td><td>something 2</td><td>something 3</td><td>something 4</td>').extend({ notify: 'always' }); 
// doesn't work with or without notify always

ko.bindingHandlers.fktml = {
    init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
        var value = ko.unwrap(valueAccessor());
        console.log(value);
        addUpdatedHtml(element, value);
    },
    update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
        var value = ko.unwrap(valueAccessor());
        console.log('update', element, valueAccessor, allBindings, viewModel, bindingContext, value);
        addUpdatedHtml(element, value);
    }
};
ko.virtualElements.allowedBindings.fktml = true;
...

对于我的foreach中的每个项目,init和update被调用一次。但是当我更新this.html()时没有任何事情发生,是的,我已经检查过它是否已更新。大多数其他答案所说的是使用ko.unwrap(valueAccessor()),它不仅在第一次给我值,而且什么都不做。

我怎样才能在这个淘汰赛中获得成功?

0 个答案:

没有答案