【问题标题】:Windows 8 Javascript: Listview invoke troubleWindows 8 Javascript:Listview 调用麻烦
【发布时间】:2014-10-21 03:59:21
【问题描述】:

我一直在使用 C# 和 Html 制作 Windows 8 应用程序之间苦苦挣扎。但由于某些功能,我决定使用 Html。但是我一直无法获得选择了哪个 Listview 项目/元素/子项(如果有)。这就是我的 HTML 中的内容:

<div id="shapeListItem" data-win-control="WinJS.Binding.Template" style="display: none;">
   <div style="width: 100px; height: 100px;">
      <img src="#" style="width: 100px; height: 100px;" data-win-bind="src: picture" />
   </div>
</div>

<div id="shapes" data-win-control="WinJS.UI.ListView" data-win-options="{itemDataSource : shapeTemplate.itemList.dataSource, 
       itemTemplate: select('#shapeListItem'),
       tapBehavior: 'toggleSelect',
       selectionMode: 'single'}">
</div>

还有我的 Javascript:

WinJS.Utilities.ready(function () { init(); });

function init() {
    var shapes = document.getElementById("shapes").winControl;
    //shapes.selected ???
}

我不记得我尝试过什么,但我从来没有成功过。 我只想获取选择了哪个项目并从中获取图像uri。或者我可以在我的数据绑定中添加另一个标题或其他内容,顺便说一下,这似乎工作正常。感谢您查看我所拥有的内容,如果您对其他任何事情有任何其他建议或方法,我们将不胜感激。或者,如果我需要发布更多代码,我会这样做。

再次感谢, 斯蒂芬

编辑: 哦,我也尝试添加“onitemInvoke:'handler'”,但出现错误。

【问题讨论】:

    标签: javascript listview windows-8 visual-studio-2013 windows-8.1


    【解决方案1】:

    文档:http://msdn.microsoft.com/en-us/library/windows/apps/br211852.aspx

    试试:

    function init() {
        var shapes = document.getElementById("shapes").winControl;
        // gets an array of the indices:
        var selectedIndices = shapes.selection.getIndices(); 
    }
    

    我给你的一个窍门是:

    function init() {
        var shapes = document.getElementById("shapes").winControl;
        debugger;
        // gets an array of the indices:
        var selectedIndices = shapes.selection.getIndices(); 
    }
    

    然后将“形状”添加到监视窗口 - 您将能够看到 API。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-11
      相关资源
      最近更新 更多