Code Monkey home page Code Monkey logo

Comments (2)

johnyanarella avatar johnyanarella commented on August 20, 2024

Claude,

If I understand what you're trying to do correctly, I have some good news. You don't need to jump through any of those hoops to avoid duplicate ids.

The selectors supplied in the control configuration for a Deft.ViewController are evaluated relative to the view. If you use itemId rather than id, you can completely avoid the duplicate id issue. You can have multiple components in the same application at different levels of the view hierarchy with the same 'itemId' (unlike with 'id').

So if you have a view like this:

Ext.create('MyApp.view.MyView', {
  extend: 'Ext.Container',
  mixins: ['Deft.Controllable'],
  controller: 'MyApp.controller.MyViewController',

  items: [
    {
      xtype: 'button',
      itemId: 'submitButton'
    },

    ...
  ],

  ...
});

And a ViewController like this:

Ext.create('MyApp.controller.MyViewController', {
  extend: 'Deft.ViewController',

  control: {
    submitButton: {
      click: 'onSubmitButtonClick'
    }
  },

  ...
  onSubmitButtonClick: function() {
     // TODO: Do something.
  }
});

You can create as many independent instances of MyApp.view.MyView as you want.

Each will get its own instance of MyApp.Controller.controller.MyViewController backing it.

Each of those MyViewController instances will evaluate the selectors provided via the control annotation relative to that view instance. In the example above, the selector is implicit - it will query for '#submitButton' within that view instance. (You can provide explicit selectors if needed through more verbose syntax, as shown on http://deftjs.org/)

So, that's an important distinction - Ext.Controller selectors are global, whereas Deft JS View Controller selectors are relative.

The problem of displaying multiple copies of the same view (each backed by independent view-specific controllers) is one of the problems Deft JS was built to solve.

Let me know if I understood your issue correctly, and if this helps resolve the problem you were having.

Best regards,

-J

from deftjs.

cgauthier avatar cgauthier commented on August 20, 2024

Perfect John! exactly what I wanted.. using itemId is the solution.. whoo hoo! :)

from deftjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.