Javascript Using a copied image in listview issue RRS feed

  • Question

  • My listView: 

     <div id="employeeList" data-win-control="WinJS.UI.ListView" data-win-options="{itemDataSource : myData.dataSource, 
                                itemTemplate: select('#employeeTemplate'), 
                                selectionMode: 'none', tapBehavior: 'invoke', layout: { type: WinJS.UI.GridLayout, maxRows: 1 } } ">

    My template: 

     <div id="employeeTemplate" data-win-control="WinJS.Binding.Template">
                        <div style="width: 238px; height: 340px;" >
                            <div class="containerEmployee" id="containerEmployee">
                               <img src="#" width="250" height="340" data-win-bind="src : txPath" />
                                <div class="divName">
                                    <!-- Displays the "title" field. -->
                                    <h1 data-win-bind="innerText: txName"></h1>
                                    <!-- Displays the "text" field. -->

    and there's the issue: 
    when I use an image that is in project , it works fine... 

                        key: cursor.key,
                        txName: cursor.value.txName,
                        txPathImagem: "images/logo.png"

    however, if I try to use an image that user's previously uploaded, like this:

    var applicationData = Windows.Storage.ApplicationData.current;
        var localFolder = applicationData.localFolder;
                        key: cursor.key,
                        txName: cursor.value.txName,
                        txPath: localFolder + "\\" + cursor.value.txPath                    
    // log = txPath: C:\Users\alex\AppData\Local\Packages\82e21540-f595-48ed-8321-899dbd927076_kn9g90yz1j63m\LocalState\0.8469254213794696.jpg
    it does not show the image. I have searched a lot looking for a solution, can someone help me on this??

    Tuesday, May 29, 2012 3:01 PM


All replies

  • I will help you debug this yourself...

    What do you see in the debugger when you look at the value of localFolder?


    Jeff Sanders (MSFT)

    Tuesday, May 29, 2012 3:40 PM
  • LocalFolder = C:\Users\alex\AppData\Local\Packages\82e21540-f595-48ed-8321-899dbd927076_kn9g90yz1j63m\LocalState\

    cursor.value.txPath  = 0.8469254213794696.jpg

    Alex Nosse

    Tuesday, May 29, 2012 5:41 PM
  • Looks like your code would add an extra '\'


    Also Can you browse to the image using windows explorer?


    Jeff Sanders (MSFT)

    Tuesday, May 29, 2012 6:08 PM
  • the first \ is a escape to the second \...

    if I wrote 

     txPath: localFolder + "\" + cursor.value.txPath

    the code won't execute, because it have a sintax error... 

    Yes, i can see the image in windows explorer...

    There's some restriction around absolute paths in list view data binds? 

    Alex Nosse

    Tuesday, May 29, 2012 6:22 PM
  • I meant eliminate it.

    LocalFolder = C:\Users\alex\AppData\Local\Packages\82e21540-f595-48ed-8321-899dbd927076_kn9g90yz1j63m\LocalState\

    cursor.value.txPath = 0.8469254213794696.jpg

    txPath: localFolder + "\\" + cursor.value.txPath                   

    txtPath = C:\Users\alex\AppData\Local\Packages\82e21540-f595-48ed-8321-899dbd927076_kn9g90yz1j63m\LocalState\\ 0.8469254213794696.jpg

    Jeff Sanders (MSFT)

    Tuesday, May 29, 2012 6:25 PM
  • Oh, I see... 

    sorry, I didn't notice early... 
    I eliminated it, but it still doesn't work... 

    * So, can you give me some directions how to put absolute paths in image src inside a listview?

    Alex Nosse

    Tuesday, May 29, 2012 6:31 PM
  • Hi Alex,

    I should have noticed earlier... You cannot have a full file path.

    For an image source in your local directory you would do something like this:

    img.src = "image.png"

    Jeff Sanders (MSFT)

    Tuesday, May 29, 2012 6:39 PM
  • I'm giving users a way to upload their own images, and protect these images to be manually deleted, for this I use 

    var localFolder = Windows.Storage.ApplicationData.current.applicationData.localFolder;

    to store these images. 

    you're saying there's no way to bind these images to my listview, is that correct??

    Alex Nosse

    Tuesday, May 29, 2012 7:02 PM
    • Marked as answer by Alex Nosse Tuesday, May 29, 2012 8:14 PM
    Tuesday, May 29, 2012 8:10 PM
  • Thanks a lot!! 

    Alex Nosse

    Tuesday, May 29, 2012 8:15 PM