WinJS.Binding多个来源

时间:2013-04-15 06:00:59

标签: javascript data-binding windows-8 winjs

我是数据绑定的新手,但它看起来像是一种简单的方法来实现我需要做的事情。

我的问题(如您所见)是我有两个(或更多)这些框在每个页面上有不同的数据。代码工作正常,但在两个div中显示相同的内容

这是我的示例代码:

使用Javascript:

var people = {
   name: "Jeff",
   age: 37,
   location: "New Jersey"
}

var animals = {
   name: "Kiki",
   age: 2,
   location: "Canada"
}

var elementPeople = document.getElementById("peopleBox");
var bindingSrcPeople = WinJS.Binding.as(people);

var elementAnimals = document.getElementById("animalBox");
var bindingSrcAnimals = WinJS.Binding.as(animals);

.
.
.

WinJS.Binding.processAll(elementPeople, bindingSrcPeople);
WinJS.Binding.processAll(elementAnimals, bindingSrcAnimals);

HTML:

<div id="peopleBox">
  <div class="" data-win-bind="textContent:name"></div>
  <div class="" data-win-bind="textContent:location"></div>
</div>


<div id="animalBox">
  <div class="" data-win-bind="textContent:name"></div>
  <div class="" data-win-bind="textContent:location"></div>
</div>

任何帮助将不胜感激。非常感谢你。

0 个答案:

没有答案