Single Page Application: Data Problems

77 views
Skip to first unread message

Dominik Steinle

unread,
Jan 30, 2018, 3:39:47 AM1/30/18
to KnockoutJS
Hi Together ,


i tried to change the Single Page applications Tutorial to get my own data in the table. (lean.knockoutjs.com) So when I change to folder Archive, the other data set are not shown only the data from the Inbox are shown. I don't understand what I am doing wrong.


 HTML:

<!-- Folders -->
<ul class="folders" data-bind="foreach: folders">
    <li data-bind="text: $data,
                   css: { selected: $data == $root.chosenFolderId() },
                   click: $root.goToFolder"></li>
</ul>

<!-- Mails grid -->
<table class="mails" data-bind="with: chosenFolderData">
    <tbody data-bind="foreach: mails">
        <tr>
            <td data-bind="text: date"></td>
        </tr>    
    </tbody>
</table>

 

JavaScript:
function WebmailViewModel() {
    // Data
    var self = this;
    self.folders = ['Inbox', 'Archive', 'Sent', 'Spam'];
    self.chosenFolderId = ko.observable();
    self.chosenFolderData = ko.observable();

    // Behaviours    
    self.goToFolder = function(folder) {
        self.chosenFolderId(folder);
     
        simulatedResults = [{date: 'test1'}];
       
        if (folder == 'Inbox'){
       
       
       $(self.chosenFolderData = ({mails:simulatedResults}));
       
        }
        else if (folder == 'Archive') {
         simulatedResults2 = [{date: 'test2'}];      
         $(self.chosenFolderData = ({mails:simulatedResults2}));
         
       
        }
       
    };

    // Show inbox by default
    self.goToFolder('Inbox');
};

ko.applyBindings(new WebmailViewModel());

Gunnar Liljas

unread,
Jan 30, 2018, 7:21:41 AM1/30/18
to knock...@googlegroups.com
The $ parts look strange.

$(self.chosenFolderData = ({mails:simulatedResults2}));

should be

self.chosenFolderData({mails:simulatedResults2});

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

asds

unread,
Jan 31, 2018, 4:40:34 AM1/31/18
to KnockoutJS
thanks, that's the solution.
how does it work, when I have two "foreach data-bind" in  one "with data-bind"  ???
How can I access independent to one of the foreach data-bind ??
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.

Gunnar Liljas

unread,
Jan 31, 2018, 8:27:22 AM1/31/18
to knock...@googlegroups.com
I don't quite understand the question. Could you rephrase/show?

To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+unsubscribe@googlegroups.com.

asds

unread,
Feb 1, 2018, 2:33:05 AM2/1/18
to KnockoutJS
I opened a new topic find under "more then one foreach data-binds ".
Reply all
Reply to author
Forward
0 new messages