Durandal JS knockout Deferred updates

Daxxy

I am having an issue when enabling deferred updates in the knockout library. I have implemented Jquery datatables as a component, when navigating to a view that has this component i can see the following methods being called in order. Getview>Activate>Attach

everything works as expected

But if i press f5 and refresh the page rather than navigating to it from another page it breaks and the following methods are called

Getview>Activate>Attach>Getview>Activate>Attach>Detach>Detach (not sure why its called twice in the end) and it breaks, no table shows on the UI at all as it does not render from what i can tell, i think it has something to do with durandal transitions and there being a difference between navigating to a page and refreshing a page kinda grasping at straws tho.

This is a minimal class that replicates the problem for me, note i dont have an HTML file for this component i want to use the getView method to pass in some dynamic HTML from JQueryDT

I created a quick sample project with the bare minimum needed to replicate the problem. https://bitbucket.org/dchosking1988/deferred-update-example

If you pull that and run it you will see that the "hello world" will disappear when you refresh the page but it wont if you navigate between tabs.

the general steps i used to replicate the issue are

1) download sample project

2) add test component (see repo above for the sample file)

3) enable deferred updates

4) disable view caching

4) try compose new instance of the component

Edits to give more info

*This is not a JQuery Datatable problem, it is replicated with the following

So you dont have to download the gitRepo, this is the code i can replicate the problem with in the sample project following the above steps.

define([],
function () {
    var test = function () {
        var self = this;

        var defaultViewHtml = '<div> <h1>Hello World</h1></div>';
        var currentView = null;

        self.getView = function () {
            console.log('GetView');
            if (!currentView) {
                currentView = $(defaultViewHtml)[0];
            }
            return currentView;
        };

        self.activate = function (activateOptions) {
            console.log('Activate');
        };

        self.attached = function (view, parent, settings) {
            console.log('Attatched');
        };

        self.detached = function (view, parent) {
            console.log('Detatched');
        };
    };

    return test;
});

Then Add this HTML to the index.html, also dont forget to create an instance of the class in the index.js

 <div class="whiteRow">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div data-bind="compose: { model: test }"></div>
            </div>
        </div>
    </div>
</div>
Igor Paiva

This is occurred because it call code twice and second called the currentView stay empty in test.js, I commented the stretch where you set the currentView and code work.

self.getView = function () {
               console.log('GetView');
               //if (!currentView) {
               //    currentView = $(defaultViewHtml)[0];
               //}
               return currentView;
               };

-

<div class="whiteRow">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div data-bind="compose: { model: test }"></div>
            </div>
        </div>
    </div>
</div>

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Durandal knockout array undefined

分類Dev

How can I integrate FusionChart in my SPA application developed using Durandal and Knockout?

分類Dev

Knockout js binding not updating

分類Dev

Knockout Js:foreachBinding

分類Dev

Knockout.js binding scope

分類Dev

Number input box in Knockout JS

分類Dev

Component communication in Knockout.JS

分類Dev

Knockout js checkbox checked binding

分類Dev

MVCとKnockout.js

分類Dev

Update an array item in knockout js

分類Dev

Knockout JS and DataTables Ajax and PHP

分類Dev

Durandal /Require.jsでLinq.jsを使用する

分類Dev

Knockout.js ko.dataFor

分類Dev

What is evaluator function in knockout.js?

分類Dev

knockout.js observable groups/computed groups

分類Dev

ObservableArrayの更新-Knockout.js

分類Dev

knockout.js foreach $data AND $index()?

分類Dev

Updating individual fields in an ejGrid with Knockout.js

分類Dev

Multilevel Menu using Knockout JS and Bootstrap

分類Dev

shell.jsでrequire( 'durandal / app')はできません

分類Dev

TypescriptとDurandal.JSとエクスポート

分類Dev

Knockout JS: How should "with" or clearnNode be used to deal with Multiplle bindings error with knockout js?

分類Dev

ifindexで$ indexを使用するknockout.js

分類Dev

How to use knockout.js with ASP.NET MVC ViewModels?

分類Dev

リンクを作成する-Knockout.js

分類Dev

Knockout JS binding element's property to another element

分類Dev

Magento 2 Knockout XML->PHTML->JS->HTML

分類Dev

Knockout.js JqueryUI Autocomplete Binding - Return the Object instead of the value

分類Dev

Does knockout.js really employ MVVM pattern?

Related 関連記事

ホットタグ

アーカイブ