Ways to display or conceal dual views within a single Marionette js region

In my LayoutView, I have set up two regions: the filter region and the main region (Content Region). The main region displays a view based on the selection made in the filter region.

Currently, I have a view for the main region called Current Year view. However, I need guidance on creating a view for a different Wireframe that is attached to this question panel.

// Application Bootstrap
var App = new Marionette.Application();

// Add a region
App.addRegions({
  main: "#app"
});

/*DATA*/
var data = {
  "accounts": [{
    "accountNumber": "AllAccounts",
    "assets": [{
        "assetName": "ASSET 1",
        "isin": "GB0008533564",
        "grossProfit": [{
          "assetCost": "500",
          "units": "10",
          "netGainLoss": "20"
        }]
      },
      {
        "assetName": "ASSET 2",
        "isin": "GB0008533565",
        "grossProfit": [{
          "assetCost": "500",
          "units": "10",
          "netGainLoss": "20"
        }]
      },
      {
        "assetName": "ASSET 3",
        "isin": "GB0008533566",
        "grossProfit": [{
          "assetCost": "500",
          "units": "10",
          "netGainLoss": "20"
        }]
      }
    ]
  }]
};

// Rest of the code remains same

...

.container {
  padding-top: 10px;
}
<div class="container">
  <div class="row">
    <div class="col-md-12">
      <div id="app"></div>
    </div>
  </div>
</div>

<!--TEMPLATES -->
<script id="layout-view-template" type="text/handlebars-template">
  <!-- Layout View Template HTML Code Here -->
</script>

<script id="filter-view-template" type="text/handlebars-template">
  <!-- Filter View Template HTML Code Here -->
</script>

<script id="report-view-template" type="text/handlebars-template">
  <!-- Report View Template HTML Code Here -->
</script>

<script id="report-row-template" type="text/handlebars-template">
  <!-- Report Row Template HTML Code Here -->
</script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
<!-- Include necessary CDN scripts here -->

Please use the provided data below to display the Past 2 Years view, where only slight changes are made in the grossProfit array objects.


var data = {
  "accounts": [{
    "accountNumber": "AllAccounts",
    "assets": [{
        "assetName": "ASSET 1",
        "isin": "GB0008533564",
        "grossProfit": [{
            "assetCost": "500",
            "units": "10",
            "netGainLoss": "20"
          },
          {
            "assetCost": "500",
            "units": "10",
            "netGainLoss": "20"
          }

        ]
      },
      {
        "assetName": "ASSET 2",
        "isin": "GB0008533565",
        "grossProfit": [{
            "assetCost": "500",
            "units": "10",
            "netGainLoss": "20"
          },
          {
            "assetCost": "500",
            "units": "10",
            "netGainLoss": "20"
          }

        ]
      },
      {
        "assetName": "ASSET 3",
        "isin": "GB0008533566",
        "grossProfit": [{
            "assetCost": "500",
            "units": "10",
            "netGainLoss": "20"
          },
          {
            "assetCost": "1000",
            "units": "10",
            "netGainLoss": "20"
          }

        ]
      }
    ]
  }]
};

Answer №1

When dealing with showing different composite views within the main region, there are a few cases to consider:

Case 1: If you need to display completely different composite views in the main region, create a separate layout called 'ResultLayout' to be rendered in the Main Region. Initialize both composite views in ResultLayout and switch between them based on filter changes.

In the scenario of dynamic data:

Case 2: Again, if you have to show different composite views in the main region, utilize 'ResultLayout'. Initially, display the default filter selected and corresponding view within ResultLayout. Upon filter change, trigger an event from FilterView listened to in ResultLayout to fetch the collection according to the filters and render the appropriate composite view.

The hierarchy for this case is LayoutView -> Filter Region and Main Region -> ResultLayout -> CompositeView1 or CompositeView2.

Case 3: To keep the composite view the same, simply update the collection and render the view accordingly.

I trust this explanation is helpful!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps can I take to stop my browser from displaying the "waiting for MyHostName" message while performing an ajax Post/Get operation?

Whenever I access a website using Chrome, a message appears in the status bar saying "Waiting for MyHost name" along with an Ajax Loader circle in the browser tab. Here is a javascript function that I am working with: function listen_backend_client_reques ...

Iterate through each image within a specific div element and showcase the images with a blur effect applied

I have a div with multiple images like this: <div class="am-container" id="am-container"> <a href="#"><img src="images/1.jpg"></img></a> <a href="#"><img src="images/2.jpg"></img>< ...

Improving Visibility in AngularJS

I am new to using Angular and encountering a simple issue. I have a button that, when clicked, should reveal a grid and some hidden filters. The filters are structured like this: <div ng-show="filtroFilial" style="visibility: hidden" class="col-md-2"&g ...

Navigating tables with jQuery using a loop and extracting data from two tables with matching row names

I am facing a challenge with a function that combines data from two tables, each containing a column named "name". How can I specify which table's name should be displayed? function createTableRow(customers) { var data = JSON.parse(customers.resu ...

Issues with JavaScript PHP Ajax request

I am currently developing a Single Page Application and facing challenges with Ajax. The two files I am working with are bhart.js and RespSelArt.php. However, my Ajax Call is not functioning as expected. At this point, all I want is to display "worked". H ...

When utilizing Vue JS, each key value of one computed property can trigger another computed property to run

I have a computed property: getRelatedItem () { return this.allItems.find((item) => { return item.id === this.currentSelectedItemId }) }, Here is an example of the output: relatedItem:Object -KQ1hiTWoqAU77hiKcBZ:true -KQ1tTqLrtUvGnBTsL-M:tr ...

Modify the contents of a textbox by editing the text as you type

Text within the text box follows this format: login -u username -p password When entering this text, I want to substitute 'password' with a series of '*'s equal in length. For example: 'login -u <a href="/cdn-cgi/l/email-prot ...

Maximizing Efficiency: Utilizing a Single Panel across Multiple HTML Files with jQueryMobile

Can a panel defined in index.html be used on another page, such as results.html? Or do I have to define the panel on every page and duplicate the HTML code on each page? Because I want the panel to be consistent across all pages. This is the panel in my ...

Are variables initialized before the execution of ajax?

After reviewing the code snippet provided below, can we confirm with certainty that the id variable passed in the ajax call will consistently be assigned a value of 1? Or is there a possibility that the id could potentially be null or undefined at some p ...

The image source failed to load the image using the function

Initially, I set up a sandbox to work on this issue: https://codesandbox.io/s/naughty-almeida-u66mlt?file=/src/App.js The main problem arises when the requested image fails to display after the function is called and the URL is returned. Here are my atte ...

The jQuery AJAX response consistently comes back empty

Hello, I'm currently working on creating an HTML form and I need to validate it before submitting the form action. However, when I use AJAX to respond, I keep receiving a blank message. Can anyone help me with this issue? $(function(){ $("#ajax-p ...

Issue - The 'defaultValue' is failing to load the state value, and the 'value' is not being updated when changed

My current setup involves an input field in my MovieInput.tsx file: <input id="inputMovieTitle" type="text" onChange={ e => titleHandleChange(e) } value={ getTitle() }> </input> This is how the titleHandleChange function ...

Retrieve the identifier of the higher-order block when it is clicked

When I have a parent block with a nested child block inside of it, I expect to retrieve the id of the parent when clicked. However, the event target seems to be the child element instead. Is there a way for JavaScript to recognize the parent as the event ...

Tips for keeping the scrollbar permanently at the bottom in JavaScript?

I am trying to implement a feature where a div always scrolls down automatically. scrollDown(){ var chat = this.conversation; this.conversation.scrollTop = chat.scrollHeight; } checkKeyPress(e){ if (e.key == "Enter") { this.scrollDown(); .. ...

Is it possible to minify HTML in PHP without parsing JavaScript and CSS code?

After finding a solution in this discussion, I successfully managed to 'minify' HTML content. function process_content($buffer) { $search = array( '/\>[^\S ]+/s', // eliminate spaces after tags, except for ...

If you try to wrap an object with an anonymous function, you'll receive an error message

Consider the following straightforward example. (function() { var message = { display: function() { alert('hello'); } }; })(); When trying to implement message.display(); An error is triggered stating ReferenceError: message ...

What could be the reason why the Google Maps API fails to load on Firefox?

I am currently utilizing the v3 version of Google Maps API. While my map functions perfectly in Safari and Chrome, I encountered an issue in Firefox where I received the error message "google.maps.Map is not a constructor." When inspecting 'google.ma ...

Preserve router animations using :key attribute, while ensuring that parent views do not reload

My app utilizes :key="$route.path" in the router view for transitions, but this approach leads to the child route base view being refreshed and triggering certain APIs again. Routes: { path: "/some-route", component: () => impor ...

What is the best way to selectively adjust object parameters in unit testing?

In my module, I have an object with several parameters. I want to rewire only specific parameters of this object. Here is a snippet from my 'module.js' file: var obj = { param_A: 'valueA', param_B: 'valueB', param_C: &a ...

Tips for choosing elements based on the length of an array

When using an each function, I scan the DOM to find multiple elements with a specific className. Depending on the length of this ClassName, it will create an array that is either 2 or 4 elements long. I need to distinguish between these two types of elem ...