[CLOSED] How to use the root path '/' when loading a widget?

  1. #1

    [CLOSED] How to use the root path '/' when loading a widget?

    How can I make the widget-loader use an absolute path and not a relative one?

    I tried the code below, but it will still use a relative path,

    It will look for the widget here (example): http://localhost:17158/Path1/Path2/widget/myNs/test1.js

    But I want it to look here: http://localhost:17158/widget/myNs/test1.js

    @{ 
        var x = Html.X();    
    }
    @(
        x.Panel()        
            .Items(
                x.Button()
                    .Text("Create field")
                    .Handler(@"
                        var p=this.up('panel');
                        Ext.Loader.setPath('myNs', '/');                    
                        p.add({ xtype:'myNs.test1' });
                    ")
            )
    )
    Last edited by fabricio.murta; Nov 11, 2016 at 4:52 PM. Reason: no user feedback for 7+ days
  2. #2
    Hello @sveins12!

    It is not clear to me how to reproduce your problem. Can you provide more information, maybe the full example to reproduce the issue? How are you creating your view, where you add the file in your solution? I suppose that file needs a view and a controller, and then the .js file could be located anywhere in the website, like /scripts/test.js, for example?
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Yes. Actually for the test I don't need a .js file. Just look in the debug-window->Network and see what path is being used. The problem is that the path is relative to the controller-path, and not to the root.
  4. #4
    Hello @sveins12!

    Took a while to understand what you want from the sample you provided, but I think I get it.

    You can't use a component from its xtype if the class is not already defined in the context. It can't infer class or namespace from the xtype. Xtype is just a shorthand for classes already defined in the current scope. So it does not make much sense to combine xtype component instantiation with dynamically loaded scripts/compoents.

    So, instead use this:

    p.add(Ext.create('myNs.test1'));
    Then you are effectively specifying a namespace when adding a component.

    I hope this helps. You may find more useful information about dynamically loading your custom components here:
    - Sencha Blog - Using Ext Loader for your Application

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hello @sveins12!

    It has been some days already since our last follow-up in the thread, and no feedback from you. Do you still need assistance with it?
    Fabrício Murta
    Developer & Support Expert
  6. #6
    Hello again and sorry for my late replay. I think that it is not quite correct. It seems like the framework tries to load the component from the path specified with
    Ext.Loader.setPath('myNs', '/')
    But it uses a predefined path "widget" (if I remember correctly) as the base path. Right now this is not a big problem for me, it was more out of curiosity that I wanted to ask about it, and that it could be a useful consideration when planning the system design.
  7. #7
    Hello, and thanks for the feedback!

    Well, I tried this here, and it worked when I used full class reference instead of xtype reference. I don't really understand which part you are suggesting to be wrong...

    As you noticed, it tries to find it from the generic path, because it has no idea which class to look for. A xtype is never a class, but a "shorthand" for a class. You can have several xtypes matching one class, for example. So when you give something an xtype parameter, it can only infer the actual class or namespace (which you specify as first argument of setPath()) if the xtype is already bound to a class in that context.

    I'm not sure this is clear still... Will put in a different way as a second attempt up front: a xtype has no relationship to classes. It is a shorthand for components that, in order to be usable, should already be mapped (present in scope) when they are referred to.

    I hope this clarifies why the create(<namespace+class>) works but not just an xtype. :) You gave the class/namespace a path, not a xtype a path.

    But if still doubts, let us know, we'll triple-check the information to ensure all is clear!
    Fabrício Murta
    Developer & Support Expert
  8. #8
    Thanks, I will let you know.
    Last edited by sveins12; Oct 18, 2016 at 12:11 AM.
  9. #9
    Hello @sveins12!

    It's been some days and we still didn't hear back from you. Did the suggestion provided above work for you?
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 8
    Last Post: Feb 10, 2014, 9:59 AM
  2. Replies: 8
    Last Post: Feb 15, 2012, 9:04 AM
  3. [CLOSED] Error loading pages using relative path
    By flormariafr in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 01, 2010, 9:53 AM
  4. Ext Core Rating Widget
    By sbarnes in forum 1.x Help
    Replies: 0
    Last Post: Jul 23, 2009, 8:03 PM
  5. Replies: 2
    Last Post: Nov 25, 2008, 10:46 AM

Posting Permissions