locked
How do I get the currently selected item in the HTML client? RRS feed

  • Question

  • Sorry if this is a dumb question, but I've only just started playing with the HTML client.

    Suppose I have a screen with a list of lectures, shown in a tile view. I want to add a button to the tile, so that when the user clicks it, it will download an audio file of the lecture.

    I added a button, and set the Tap event to a new method. That method gets a screen object passed to it, which has a Lectures property, which has a Count of 45, so I know I can get the Lectures collection.

    However, I want to find the specific lecture whose button was tapped. I tried screen.Lectures.SelectedItem (as that's what it's called in the screen designer), as well as screen.Lectures.selectedItem (as Javascript properties often seem to have a lowercase letter at the start), as well as various other things, but all of these were undefined.

    Anyone able to help me here? More to the point, is this stuff documented anywhere? I've been searching around MSDN and various LS blogs, but can't find any documentation on what parameters you get in these Javascript methods. Any links would be great.

    Thanks for any help.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Monday, April 8, 2013 3:22 PM

Answers

  • sorry, for screenEntity i meant "Lectures"..

    in my case i have tap event in tile list on entity called "html_Meniji" and i want to get to entity property named "komanda" (string), so i have this:

    var selitem = screen.details.properties.HTML_Meniji.value.selectedItem.Komanda;

    and im getting wanted string into "selitem"..

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)


    • Edited by Kivito Monday, April 8, 2013 3:57 PM
    • Marked as answer by Mr Yossu Monday, April 8, 2013 4:04 PM
    Monday, April 8, 2013 3:56 PM
  • Thanks for that. For some reason, the code you sent didn't work, but the following did...

    var id = screen.Lectures.selectedItem.ID;

    I'd still like to know where all this is documented.

    Thanks again for the help.

    P.S. I marked both of our posts as answers, as yours obviously works for you, and mine works for me, so between the two, they should help other people. I don't know what the difference is, but maybe if I ever find any docs, it might become clearer.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/


    • Marked as answer by Mr Yossu Monday, April 8, 2013 4:04 PM
    • Edited by Mr Yossu Monday, April 8, 2013 4:06 PM
    Monday, April 8, 2013 4:04 PM

All replies

  • hi!

    i'm also having problem to catch up with javascript and "new style" of writing.. maybe you can try with something like:

    var selitem = screen.details.properties.screenEntity.value.selectedItem;

    hth..

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Monday, April 8, 2013 3:34 PM
  • Hi Kivito, thanks for the reply. Unfortunately, the code didn't work. The "properties" property was defined, but "screenEntity" wasn't. I have no idea how I can even look at the "properties" property to see what's in it. I tried putting a breakpoint in the Javascript, but it never got hit.

    I don't have a problem with writing Javascript (actually that's a lie, I hate Javascript!), I just have a problem trying to write code when I don't have any knowledge of the data I'm given. If Microsoft did as good a job of documentation as they did on the actual code, I'd be flying by now.

    Any idea how I'm supposed to find out what I've got here? I feel like the proverbial blind man in the dark cellar looking for the black cat that isn't there! Surely there must be some small hints around as to how we use this stuff?

    Thanks again, any more suggestions very welcome.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Monday, April 8, 2013 3:46 PM
  • sorry, for screenEntity i meant "Lectures"..

    in my case i have tap event in tile list on entity called "html_Meniji" and i want to get to entity property named "komanda" (string), so i have this:

    var selitem = screen.details.properties.HTML_Meniji.value.selectedItem.Komanda;

    and im getting wanted string into "selitem"..

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)


    • Edited by Kivito Monday, April 8, 2013 3:57 PM
    • Marked as answer by Mr Yossu Monday, April 8, 2013 4:04 PM
    Monday, April 8, 2013 3:56 PM
  • Thanks for that. For some reason, the code you sent didn't work, but the following did...

    var id = screen.Lectures.selectedItem.ID;

    I'd still like to know where all this is documented.

    Thanks again for the help.

    P.S. I marked both of our posts as answers, as yours obviously works for you, and mine works for me, so between the two, they should help other people. I don't know what the difference is, but maybe if I ever find any docs, it might become clearer.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/


    • Marked as answer by Mr Yossu Monday, April 8, 2013 4:04 PM
    • Edited by Mr Yossu Monday, April 8, 2013 4:06 PM
    Monday, April 8, 2013 4:04 PM
  • 1.  IntelliSense is the best tool.  Do you get good IntelliSense when you write e.g. “screen.” ? 
     
    2.  If not, can you debug in the IDE?  Set a breakpoint in your function and inspect the parameters to see what is in them.
     
    3.  If not, use the script debugger in your browser to achieve the same purpose as #2.  For some reason, in CTP 4, the debugger was showing me more accurate object members than the browser debugger (both IE 10 and Chrome).
     
    -- David

    Efficiently read and post to forums with newsreaders: http://communitybridge.codeplex.com
    Monday, April 8, 2013 4:26 PM
  • yeah, i'm also waiting for docs, or blogs, or.. intellisense can break if you have some complicated expression with error (parenthesis or similar), so sometimes i can't get to show anything for already working command.. and after clean/rebuild, then it shows again, but ok, better something then nothing.. 

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Monday, April 8, 2013 4:32 PM
  • There is a wealth of HTML Client knowledge in the (just recently closed) forum:  http://social.msdn.microsoft.com/Forums/en-US/lightswitchhtml/threads
     
    Particularly the MSFT posters like Huy (who I’m very glad to see is still posting here), Henrich, Joe Binder, Stephen Provine, and several others.  The most definitive doc is the LightSwitch Team blog.  Still no substitute for extensive doc, but ....
     
    -- David

    Efficiently read and post to forums with newsreaders: http://communitybridge.codeplex.com
    Monday, April 8, 2013 4:43 PM
  • Hello David, thanks for the replies.

    I get some Intellisense, but not enough. For example, when I look at the contentItem parameter of a render method, I don't see the view model stuff.

    As I mentioned before, I can't debug at all. I place breakpoints, but they aren't hit in the IDE. Since posting, I tried the f12 stuff in IE, which does work, and that's how I got some answer to my problem. Even so, it's a pretty painful experience.

    As for the forum, I have looked through there, but it's hard to find specific info amongst all the discussions. I'm picking up bits here and there, but it's a very slow and painful to learn. There should be some MSDN documentation that explains how to use the stuff. I've seen the "How to" videos, but they are very basic (especially for someone who's been bashing LS for over a year), and don't dig into the Javascript at all.

    Thanks again.


    FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers. Download from the Visual Studio Gallery.

    If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at http://dotnetwhatnot.pixata.co.uk/

    Monday, April 8, 2013 4:58 PM
  • My IntelliSense sometimes works and sometimes does not.  I swear, all I do is reboot, and it starts working, but probably some other project setting buried deep got reset, and it starts working.  You might also want to try installing Resharper, as that IntelliSense does seem to work (though see posts here about bugs, now fixed, that prevent LightSwitch projects from being created).
     
    My breakpoints also sometimes do not work.  You can find my posts in the closed forum to find out that I had to load an ASP.NET MVC project and set the debugger options in it for LightSwitch debugging to work.
     
    I find it best to search for “Huy Nguyen” and see what he has to say.  :-)
     
    Don’t forget to check out the LightSwitch Team blog.  It links to Javascript samples http://code.msdn.microsoft.com/JavaScript-for-LightSwitch-f1ec057c
     
    I started becoming serious about LightSwitch with the HTML client (was never interested in deploying Silverlight) in the CTP’s of Update 2, and I have to say that now is the best time to learn the HTML stuff, even with all the startup pain.  There is a ton of support from the team.  I think they know they are trying something new and unproven and are trying to make this a mature product as fast as possible.
     
    Thanks,
    David

    Efficiently read and post to forums with newsreaders: http://communitybridge.codeplex.com
    Monday, April 8, 2013 5:40 PM