1

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

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

这是我的示例代码:

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>

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

4

0 回答 0