Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6994111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:51:02+00:00 2026-05-27T19:51:02+00:00

EDIT I made a screen shot to show better what I’m attempting to do,

  • 0

EDIT

I made a screen shot to show better what I’m attempting to do, and the problems I’m having:

enter image description here

I’m creating a list of Room objects with Knockout. I have code that displays a table of rooms as new rooms are added – using data-bind="foreach: rooms". The rooms are added with a JQuery UI modal popup that displays a form simply asking for the ‘name’ of the room.

This works fine – but I also need to display a graphical representation of each room underneath the table list – simply using css class to give a standard width, height, and color to the rooms.

Here is the entire javascript code:

$(function(){

    function Room(data) {
        this.name = ko.observable(data.name);

    }   


    function RoomViewModel() {
        var self = this;
        self.rooms = ko.observableArray([]);
        self.newRoomText = ko.observable();


        $("#hidden-button").click(function(e) {         
            e.preventDefault();         
        })

        self.addRoom = function() {
            self.rooms.push(new Room({ name: this.newRoomText() }));
            self.newRoomText("");       
            $("#modal").dialog("close");        
        }

        self.removeRoom = function(room) {
            self.rooms.remove(room)
        }

        self.RoomModal = function() {   

            $("#button-add-room").attr("disabled", "disabled"); 

            $("#input-room-name").keypress(function(e) {
                if($(this).val() != '') {
                    $("#button-add-room").removeAttr("disabled");   

                } else {
                    $("#button-add-room").attr("disabled", false);
                }           
            })

            $("#modal").dialog({
                height: 400,
                width: 400,
                modal: true
            });
        }

    }

    ko.applyBindings(new RoomViewModel());

});

When I add the container below the container that holds the table, the app ignores some of the code in the ‘self.addRoom’ function. It will add the room to the list, but the modal window will no longer close – using $("#modal").dialog("close");. It also ignores the self.newRoomText(""); code that clears out the input value to get it ready for a new room.

<!--******* Rooms List **********-->
        <div id="room-list-view">
            <table>
                <tbody data-bind="foreach: rooms">
                    <tr>
                        <td data-bind="text: name"></td>
                        <td><a href="#" data-bind="click: $parent.removeRoom">Delete</a></td>
                    </tr>
                </tbody>
            </table>
        </div>

        <!-- IF I COMMENT THIS PART OUT, IT WORKS JUST FINE -->
         <div id="graphical-room-view">
            <ul data-bind="foreach: rooms">
                <li class="graphical-room" data-bind="text: room"></li>
            </ul>

        </div> 

As you can see, if I comment out the div with id=”graphical-room-view”, the app works just fine.

Is it possible to use a foreach binding for the same array in two different places within my view? Am I going about this the wrong way – should I have a 2nd ViewModel?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:51:03+00:00Added an answer on May 27, 2026 at 7:51 pm

    In your second foreach you’re not using text: name but text: room. May be the issue 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I had made a mistake during the debugging session that lead me to
EDIT Taking COST 100 out made the command go through, however, I'm still unable
I made some modifications to SVG Edit which contains a make file. When I
-edit- nevermind, i made a mistake in my select statement. Update was working correctly.
I made a small project where i try to change the name from edit
IMPORTANT EDIT: Sorry everyone, i made a big mistake in the structure. char *name;
When i try to a edit a entry.. its creating a duplicate entry in
Im trying to print (show in screen ) a screenshot on my main monitor
i am making an edit Screen of my Account. My account class has some
I made a project where two textviews are on screen.I set two audio for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.