windows-8 – 向WinJS.Binding.converter()函数发送多个参数
发布时间:2021-01-29 13:36 所属栏目:52 来源:网络整理
导读:有没有办法将多个参数发送到WinJS.Binding.converter()函数?考虑以下数据和输出: { contactName: "Tara Miller",mainNumber: "555-405-6190",alternateNumber: "555-209-1927" },{ contactName: "Bryan Bond",alternateNumber: "555-574-4270" },{ contact
有没有办法将多个参数发送到WinJS.Binding.converter()函数?考虑以下数据和输出: { contactName: "Tara Miller",mainNumber: "555-405-6190",alternateNumber: "555-209-1927" },{ contactName: "Bryan Bond",alternateNumber: "555-574-4270" },{ contactName: "Jenna Siever",mainNumber: "555-843-8823",alternateNumber: "555-799-5424" }, 这是HTML. MyData.chooseBestNumber转换器函数用于显示某人的主要电话号码或“无主号码”字样(如果他们没有主号码): <div id="listViewTemplate" data-win-control="WinJS.Binding.Template"> <div class="contactCard"> <div data-win-bind="innerText: contactName"></div> <div data-win-bind="innerText: mainNumber MyData.chooseBestNumber"></div> </div> </div> 这是定义转换器函数的JS: WinJS.Namespace.define("MyData",{ chooseBestNumber: WinJS.Binding.converter(function (mainNumber) { if (mainNumber) return mainNumber; else return "no main number"; }),}); 下面是我最终能够做到的…将多个参数传递给转换器函数,以便我可以返回主号码(如果已定义),备用号码(作为后备),或消息(如果所有其他方法都失败): WinJS.Namespace.define("MyData",{ chooseBestNumber: WinJS.Binding.converter(function (mainNumber,alternateNumber) { if (mainNumber) return mainNumber; else if (alternateNumber) return alternateNumber; else return "no phone numbers"; }),}); 是否可以向WinJS.Binding.converter()函数发送多个参数? 解决方法您实际上可以将您的电话号码div绑定到this关键字,这将有效地将该div的innerText属性绑定到整个模型对象.在您的转换器中,您可以访问整个模型.所以你更新的代码看起来像这样: HTML <div id="listViewTemplate" data-win-control="WinJS.Binding.Template"> <div class="contactCard"> <div data-win-bind="innerText: contactName"></div> <div data-win-bind="innerText: this MyData.chooseBestNumber"></div> </div> </div> JavaScript转换器 WinJS.Namespace.define("MyData",{ chooseBestNumber: WinJS.Binding.converter(function (model) { if (model && model.mainNumber) return mainNumber; else if (model && model.alternateNumber) return alternateNumber; else return "no main number"; }),}); (编辑:ASP站长网) |
相关内容
网友评论
推荐文章
热点阅读