How to get the string value of a listview item

4 posts, 0 answers
  1. Ron
    Ron avatar
    2 posts
    Member since:
    Mar 2016

    Posted 19 Sep Link to this post

    I have built a Telerik-based mobile Platform app that references a database that has thousands of rows of text data.  When a user searches for a text value, the system shows a list of matches from a single field from the set of matching records.  When the user selects one of these items the system then displays a new screen that shows all of the fields from the selected record in what I believe is a ListView.  That all works perfectly.  

    In the Javascript area in the Custom Code area below all of this auto-generated content, I want to be able to reference or copy into a variable two of the read-only database fields (one titled Between and the other Located) that have been displayed in the ListView area for this record.

    Trouble is, I've not been able to figure out how to actually reference the data fields to be able to extract and use the actual value in my Javascript code.  I've spent the day scouring the Telerik documentation, but to no avail.  

     

    The auto-generated code displays the value for the Between field with this line:  <div data-bind="html: currentItem.Between"></div>

    Any advice or solution you can suggest would be most appreciated!

    Here's the key, system-generated code for the page, FYI;

    <div data-role="view" data-title="Details" data-model="app.searchResults.searchResultsModel" data-bind="events: { show: detailsShow }" id="searchResultsModelDetailsView">    
    <
    header data-role="header">
    <div data-role="navbar" class="header-text">
    <a data-role="backbutton" data-align="left">Back</a>
    <span data-bind="text: currentItem['Inscription']"></span>
     </div>
     </header>

     

     <div class="details-content">
     <div class="km-listview-wrapper">
     <ul class="km-listview km-list km-listinset details-fields">
     <li>
     <h3 data-bind="text: currentItem.Inscription"></h3></li>
     
     <li class="detail-content-item">
     <div class="editableListItem">
     <div>The car is located between the key blocks of:</div>
     <div data-bind="html: currentItem.Between"></div>
     </div>     

  2. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 21 Sep Link to this post

    Hi Ron,

    In the custom code block, you can overwrite the function that accesses the details and add logic that gets you the needed values. Since, in this code block, the only accessible functions are the master view event handlers, I use one of them to get the data:
    // START_CUSTOM_CODE_searchResultsModel
    // Add custom code here. For more information about custom code, see http://docs.telerik.com/platform/screenbuilder/troubleshooting/how-to-keep-custom-code-changes
    app.searchResults.onShow = function () {
        app.searchResults.searchResultsModel.setCurrentItemByUid = function (uid) {
            var item = uid,
                dataSource = this.get('dataSource'),
                itemModel = dataSource.getByUid(item),
                between = itemModel.get("Between"),
                located = itemModel.get("Located");
     
            alert("Between: " + between + "; Located: " + located);
     
            // Add rest of setCurrentItemByUid logic below.
            // You should copy it from the code above to make sure that no functionality is lost.
        }
    }
    // END_CUSTOM_CODE_searchResultsModel

    Let me know if this works for you.

    Regards,
    Tsvetina
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Ron
    Ron avatar
    2 posts
    Member since:
    Mar 2016

    Posted 30 Sep in reply to Tsvetina Link to this post

    Hi Tsvetina,

    Thanks so much for your suggestion and code!  Unfortunately, I'm not having any success in getting it to work.  I'm probably not calling it correctly as I'm not able to even get the Alert dialog to appear.

    My JavaScript skills are probably to blame.  Can you suggest with code how I can call this function and reference its values such as Between?

    Thanks!

  4. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 05 Oct Link to this post

    Hello Ron,

    Both the onShow and setCurrentItemById are expected to be called by the existing code in the app, you shouldn't need to call them explicitly.
    You can check if there are any JavaScript errors that block the execution of the entire function by pressing F12 in the simulator to bring up the browser developer tools and check the Console tab for errors.

    You can also open a support ticket and send us your project, so we can debug it and see what is missing. Or you can give us its name and we will try to get it from the Telerik Platform cloud.

    Regards,
    Tsvetina
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top