none
Entity Collection Intellisense Support in HTML Client Issues RRS feed

  • Question

  • Trying to work with screen properties representing entity collections that are stored in the Data Workspace in the HTML Client have been presenting some major challenges to me. For example, in the view model below, "Description" is a child entity of ICD9Database that is added to the screen as a query item called CommonDiagnoses.

    In any function(screen) routine, screen.ICD9Database, screen.CommonDiagnoses.[etc.] are not recognized by Intellisense nor defined, and while screen.findContentItem("Description") is defined as an object, its .value or .stringValue or .selectedItem is not.

    Groveling around in the locals window, I am able to find the value of CommonDiagnoses(item).Description here:

    screen.details.__dependencies[0]._selectedItem.details._.Description;

    That took a little bit of luck and too much time, honestly.  Is there an easier way?  I did come across this method:

    screen.getCommonDiagnoses();  --A WinJS Promise object, but no Intellisense hints for arguments

    Groveling around again, I got the correct value:

    screen.getCommonDiagnoses("Description")._value._selectedItem.details._.Description;

    I'm open to still yet easier ways though.

    Thursday, May 2, 2013 2:33 AM

Answers

  • Hi,

    JavaScript Intellisense is an external component that LightSwitch depends on, and it does not scale very well in large project. We're actively working on fixing that.

    Regarding to the Visual Collection for Screen Collection Properties, let me try to give you an overview. Let's say you have a Customers screen collection property.

    • screen.getCustomers() will return a Promise object that will be fulfilled when the Customers Visual Collection is loaded. This is the one exposed under Intellisense, because most of the time it's what you want to use.
    • screen.Customers will return the Visual Collection representing the Customers on the screen. This is hidden from Intellisense because when you access it, it's not guaranteed that the Visual Collection is loaded. But it's useful to set up change listener, etc. I believe I use it most of the time in my samples.
    • screen.Customers.data will return an array of all Customers loaded into the Visual Collection.
    • screen.Customer.selectedItem will return the current selected Customer in the Visual Collection.

    So in your case what you want is screen.CommonDiagnoses.selectedItem.Description.

    Best regards,
    Huy

    Thursday, May 2, 2013 5:37 PM

All replies

  • Hi,

    JavaScript Intellisense is an external component that LightSwitch depends on, and it does not scale very well in large project. We're actively working on fixing that.

    Regarding to the Visual Collection for Screen Collection Properties, let me try to give you an overview. Let's say you have a Customers screen collection property.

    • screen.getCustomers() will return a Promise object that will be fulfilled when the Customers Visual Collection is loaded. This is the one exposed under Intellisense, because most of the time it's what you want to use.
    • screen.Customers will return the Visual Collection representing the Customers on the screen. This is hidden from Intellisense because when you access it, it's not guaranteed that the Visual Collection is loaded. But it's useful to set up change listener, etc. I believe I use it most of the time in my samples.
    • screen.Customers.data will return an array of all Customers loaded into the Visual Collection.
    • screen.Customer.selectedItem will return the current selected Customer in the Visual Collection.

    So in your case what you want is screen.CommonDiagnoses.selectedItem.Description.

    Best regards,
    Huy

    Thursday, May 2, 2013 5:37 PM
  • To add to the bigger picture, anything that begins with an underscore ('_') or double underscore is an internal LightSwitch item and should not be used in your code (unless of course you created an item that begins with an underscore - you can use that item).

    Microsoft reserves the right to make changes to their internal naming conventions without notifying customers or providing support for our usage of those internal details.

    So if you write code that references any internal LightSwitch item, like '._selectedItem', it could break in future releases of LightSwitch and you will be on your own because it was not part of the publically published programming model.

    However, many of the items you see with a leading underscore, like '._selectedItem', are internal references to similar externally published items, like .selectedItem in this case.

    I don't think Microsoft has published the full programming model in MSDN yet, so in the meantime (and always) you can come to this forum and ask, and there are many people who can help you find the correct syntax.

    Happy Computing!


    -Christopher DeMars

    Thursday, May 2, 2013 6:10 PM
  • Thursday, May 2, 2013 6:38 PM
  • Thanks, I thought I had tried that, but possibly I was still disoriented from being temporarily trapped in a never ending tree lists of + [prototype] + [method] windows.  I won't be doing that again.
    Thursday, May 2, 2013 6:46 PM
  • screen.findContentItem("Description") returns a ContentItem object which is part of the View Model (MVVM). while you can get to the actual entity from contentItem.value, you can get to the same entity directly from the screen object.

    For example, if you have a screen with a entity called House, and the House entity has a property called Color, you can get the color by using 'screen.House.Color'.

    If you instead added a query data item to the screen that is a House collection, called HousesCollection, you could likewise get the color of the selected House using 'screen.HousesCollection.selectedItem.Color'.

    Now, you could get to the same place for a single entity in a much more confusing manner by using: 'screen.findContentItem("House").value.Color'. This not only is ugly, but runs through a lot more code just to get to the same point.

    In general, content items != data entities.

    Content Items, being part of the View Model, are great for tasks such as setting '.isEnabled', '.isVisible' and other LightSwitch View Model properties. A typical example of using findContentItem() is in the created() method of a screen to set default visual state of screen items. Entities are not the only content items -  any screen control or element has a Content Item, such as buttons, tabs, Groups, etc.


    -Christopher DeMars

    Thursday, May 2, 2013 6:48 PM
  • I have found this solution: 

    1-Remove this file from GeneratedArtifacts folder in the HTMLClient project: viewModel.intellisense.js

    2-Rebuild your project.

    3-Go to tools->options-Text Editor->JavaScript->Intellisense->References, in the reference group choose Implicit (Web), then add the new generated file viewModel.intellisense.js as a reference.

    this is worked for me...


    AAK


    Wednesday, May 15, 2013 12:12 PM
  • After some investigation, I have found the cause of the problem (I hope).

    forgot the preview solution.

    after opening the UserCode in the HTMLClient project, I have found that some js files are empty. these files I think represent the scripts for each screen created by the user. when your, for example, want to write code when the screen is created, you simply press the created menu item in the designer view of the screen, and a js file is created for this screen that hold all the user code....

    however I noticed that some js files does not contains on top this statement:

    /// <reference path="../GeneratedArtifacts/viewModel.js" />

    in this case, the intellisense will not work ! you should add this statement manually on the top of the file.

    why this statement does not exist all the time in some js files in the UserCode folder ? I don't know !

    however, I think this is the solution :)


    AAK

    Thursday, May 16, 2013 8:31 AM
  • I have found also that moving a solution from computer to computer, or folder to folder, cause the intellisense to stop working.

    AAK

    Thursday, May 16, 2013 8:36 AM