Search The ForumSearch   RegisterRegister  LoginLogin

AfterLogic WebMail Lite 7

 AfterLogic Forum : AfterLogic WebMail Lite 7
Subject Topic: Problem knockout.js on Webmail Lite Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
Ayumiesan
Newbie
Newbie


Joined: 03 March 2016
Online Status: Offline
Posts: 11
Posted: 05 May 2016 at 2:26am | IP Logged Quote Ayumiesan

Hi,
i try to applying building on Ajax content, Here my javascript Code :

//Call of my popup
App.Screens.showPopup(AttachJDWPopup);

function AttachJDWPopup() {
    this.files = ko.observableArray();
}
AttachJDWPopup.prototype.popupTemplate = function (){
    return 'Popups_AttachJDWPopupViewModel';
};
AttachJDWPopup.prototype.onShow = function (){
   this.getFiles();
};
AttachJDWPopup.prototype.getFiles = function(){
    var self = this;
    $.ajax({
        type: 'POST',
        url: './test.php',
        success: function(jqXHR){
            $('#testAffichage').html(jqXHR);
            self.files(jqXHR);
        }
    });
}
AttachJDWPopup.prototype.onItemClick = function (){
    console.log("clickItem");
};

Here, my template use :

<div class="mask" data-bind="click: onCancelClick"></div>
<div class="popup_panel">
    <span class="close" data-bind="click: onCancelClick"></span>
    <div class="panels">
        <div class="panel files">
            <div class="panel_content" id="testAffichage">
            </div>
        </div>
    </div>
    <div class="buttons">
        <span class="button save" data-i18n="FILESTORAGE/BUTTON_SELECT" data-bind="i18n: 'text', click: onSelectClick"></span>
        <span class="button save" data-i18n="FILESTORAGE/BUTTON_CLOSE" data-bind="i18n: 'text', click: onCancelClick"></span>
    </div>
</div>
<span class="helper"></span>

Here my code in test.php :

<p class="itemJarvis" data-bind="click: onItemClick" data-id_fichier="1">Item1</p>
<p class="itemJarvis selected" data-id_fichier="2">Item2</p>

At this moment, i can open the popup and the binding are well applied. Now, i want to put some text using ajax in my template, so i call my function "getFiles()" i have the result put on my html, that is ok, but now, i want to apply building for use my "onItemClick" function.

And when i try to put in ajax response :
    ko.applyBindings(self,document.getElementById('testAffichage'));

Apply binding work fine. But if i reload the popup Or just the content, i have an error message :
    Uncaught Error: You cannot apply bindings multiple times to the same element.

Can you help me ?
Back to Top View Ayumiesan's Profile Search for other posts by Ayumiesan
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6038
Posted: 05 May 2016 at 4:14am | IP Logged Quote Igor

The typical way that's done is:

Code:
.....
var applied = false;
.....
if (!applied){
       ko.applyBindings(self,document.getElementById('testAffichage'));
       applied = true;
}


--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide