locked
Get element value in list view

    Question

  • Hi

    I currently have the following listview template

    <div id="buttonListTemplate" data-win-control="WinJS.Binding.Template">
        <div style="width: 282px; height: 70px; padding: 5px; overflow: hidden; display: -ms-grid;">
            <div style="margin: 5px; -ms-grid-column: 2">
                <h4 data-win-bind="innerText: Name" ></h4>
                <h6 data-win-bind="myID: ID" ></h6>
            </div>
        </div>
    </div>

    I want to be able to get the value of myID but I can seem to do this. I am using the following javascript which bring back both the Name and ID. There must be a way of bringing back just one of these elements.

    eventInfo.srcElement.innerText

    Also is it possible to store more than one value in one element and call that back e.g.

     <h4 data-win-bind="innerText: Name;myID: ID" ></h4>

    If this is possible how would you use javascript get back myID?

    Thanks in advance

    Tuesday, July 9, 2013 1:00 PM

Answers

  • Hi,

    That solution would work if you only have 1 button (and since you are using a Template, I guess you have more than 1). Would be best to bind the "id" property to some value relative to that item in the list.

    Wednesday, July 10, 2013 4:10 PM

All replies

  • I found the solution below for anyone that might want to know...

    <div id="buttonListTemplate" data-win-control="WinJS.Binding.Template">
        <div style="width: 282px; height: 70px; padding: 5px; overflow: hidden; display: -ms-grid;">
            <div style="margin: 5px; -ms-grid-column: 2">
                <input type="hidden" id="buttonID" data-win-bind="value: ID"/>
                <h4 id="buttonName" data-win-bind="innerText: Name" ></h4>
            </div>
        </div>
    </div>

    and the javascript to get the individual elements...

    var intMenuID = eventInfo.srcElement.querySelector("#buttonID").value;
    var strMenuName = eventInfo.srcElement.querySelector("#buttonName").innerText;

    Wednesday, July 10, 2013 2:28 PM
  • Hi,

    That solution would work if you only have 1 button (and since you are using a Template, I guess you have more than 1). Would be best to bind the "id" property to some value relative to that item in the list.

    Wednesday, July 10, 2013 4:10 PM