【问题标题】:Durandal composing same view in foreachDurandal 在 foreach 中构成相同的视图
【发布时间】:2017-03-14 12:42:21
【问题描述】:

我必须在层次结构中组合相同的视图。 家长 - 孩子1 - 孩子2

<div id="divParent" data-bind="with: ParentObs">
   <section data-bind="compose: { view: '../views/header', model: '../viewmodels/header', activate: true, cacheViews: false , preserveContext: true, activationData: id}"></section>

   <div id="idChild" data-bind="ChildObs">
       <section data-bind="compose: { view: '../views/header', model: '../viewmodels/header', activate: true, cacheViews: false , preserveContext: true, activationData: id}"></section>
   </div>
</div>

ParentObs 和 childObs 的属性是一样的。只是 ParentObs 包含一个孩子列表。 属性是我使用 id 激活数据访问的名字和姓氏

现在我在组合视图中绑定它

问题是绑定到组合视图的最后一个 Id 反映在整个组合视图中。 我希望显示不同的数据。

我如何实现它。

header.html

<span data-bind="text: Properties().firstName"></span>
<span data-bind="text: Properties().lastName"></span>

header.js

define([],function(){
  var Properties = ko.observable();
  var activate = function(Id){
    Properties(getDataById(Id));
 }
});

getDataById 是一个轻而易举的电话

I have the same problem mentioned in this link. Can't understand the solution proposed

【问题讨论】:

    标签: html requirejs knockout-2.0 durandal-2.0 aurelia-breeze


    【解决方案1】:

    使用瞬态视图模型。 参考网址:http://www.lobsterfs.co.uk/blog/singleton-transient-durandal/

    【讨论】:

      猜你喜欢
      • 2014-04-08
      • 1970-01-01
      • 2013-04-03
      • 2013-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      相关资源
      最近更新 更多