0

我正在使用 WinJS.Binding.List() 将 Azure 移动服务数据绑定到 Listview。如何从列表视图中获取选定项的值和索引?

//Javascript
var table = client.getTable('PatientInfo');
var birthCertData = function () {
            table.read().done(function (results) {
                   birthCert = new WinJS.Binding.List(results);
                   listItems.winControl.itemDataSource = birthCert.dataSource;
               });
        };

function selectionChangedHandler() {
//what should I type here to get the selectedCell Value and index?
        }

        listItems.addEventListener("selectionchanged", selectionChangedHandler, false);

这是我的html

<div id="TemplateItem" data-win-control="WinJS.Binding.Template" style="display: none">
   <div style="display: -ms-grid; -ms-grid-columns: auto 1fr">
      <div style="-ms-grid-column: 2; margin-left: 5px; height: 40px; text-align: center; vertical-align: middle">
        <h3 data-win-bind="innerText: birthcert"></h3>
      </div>
   </div>
</div>

<div id="listItems" class="win-selectionstylefilled" 
     data-win-control="WinJS.UI.ListView"
     data-win-options="{ itemTemplate: select('#TemplateItem'), 
     layout: {type: WinJS.UI.ListLayout}, 
     selectionMode: 'single', 
     tapBehavior: 'directSelect'}">
</div>

 <div style="margin: 5px 0px 0px 72px; -ms-grid-column: 2">
    <input type="text" id="textInput" />
 </div>

屏幕截图:http: //i.stack.imgur.com/Di0BP.png

谢谢

4

3 回答 3

1

这与实际问题无关,但可能对您有所帮助。目前,您正在等待读取 WAMS 表的全部内容,然后才将列表视图的数据源设置为整个读取表。相反,我建议您创建一个本地 WinJS.Binding.List,立即将列表视图的数据源设置为它,然后当您读取 WAMS 表时,迭代生成的数组并将结果推送到绑定列表中。结果将与您所拥有的功能相同,但它会是一个更好的模式,并且允许在实际数据调用之前完成一些工作。

于 2013-06-17T21:13:04.960 回答
1

通过ListView的selection属性

function selectionChangedHandler(e) {
    var numItemsSelected = listItems.selection.count;
    var indicesSelected = listItems.selection.getIndices();
    var itemsSelected = listItems.selection.getItems();
    ...

}

ISelection界面为您提供了可用于检测选择状态的其他选项。注意事件的详细数据e.detaile.srcElement

于 2013-06-17T04:06:12.767 回答
0
 function selectionChangedHandler(e) {

                // get the index of the selected listview item
                var index= e.srcElement.winControl.selection.getIndices();
                // get the object of the selected index
                var odata = birthcert.getAt(test);
                //odata.[key] is the value of the selected listview's item.

            }

            listItems.addEventListener("selectionchanged", selectionChangedHandler, false);
于 2013-06-17T19:37:52.267 回答