有没有办法向一个函数发送多个参数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()
?