English 中文(简体)
连接2个可观测阵列和 k
原标题:Link 2 observable arrays together with knockout js

我有2个阵列。 一个领域是所有学校,另一个是这些学校所有学生的名单。 学生目标含有他们所属的学校。 我可以列出所有学校的名单,我可以列出所有学生的名单。 我愿选择一所学校(或一所学校),学生名单只向该学校的学生显示。

这里指的是我ve(咖啡):

ViewModel = () ->
    @accounts = ko.observableArray([])
    @players_to_teams = ko.observableArray([])
    @selected_players_to_teams = ko.observableArray([])
    @selected_schools = ko.observableArray([])
    null

观点:

<label for="school_selection">School</label>
<select id="school_selection" class="inline" multiple=true size="50" data-bind="options:accounts, optionsText:  Name , selectedOptions: selected_schools"></select>


<div id="player_list" class="inline">
  <table class="table table-striped">
    <thead>
    <tr>
      <th id="firstName">First Name</th>
      <th id="lastName">Last Name</th>
      <th id="position">Position</th>
      <th id="teamName">Team Name</th>
      <th id="accountId">Account ID</th>
    </tr>
    </thead>
    <tbody data-bind="foreach: selected_players_to_teams">
    <tr>
      <td data-bind="text: FirstName"></td>
      <td data-bind="text: LastName"></td>
    </tr>
    </tbody>
  </table>
</div>

在<代码>上当选的学校 变化 我需要更新<条码>所选的_游戏器_to_teams,以仅包含有在<条码>上有学校的学生记录?

是否有办法将可观测阵列连接起来,使可观测的Array成为一种功能,或者也许可以追索一个可观测的Array的信号?

最佳回答

我建议,将选定的“游戏者-to_teams”作为“ko.computed”,在选择的“学校”时进行更新,并将参与者送回选修学校。

See this jsfiddle for acode- only example: http://jsfiddle.net/MqNPm/

Tuan

问题回答

暂无回答




相关问题
How to go from DOM node to viewModel object?

When the drop function is called back, this is set to the droppable DOM node (the target) and ui.draggable is the DOM node which was dragged. Is there an idiomatic way of getting the model object ...

making fields observable after ajax retrieval in knockout.js

I am wondering how I can make certain fields observables in knockout.js that I get from an ajax call without having to define the whole object in my viewmodel. Is this possible? Here is what I have ...

ASP.NET MVC Validation with jQuery $.ajax

I have a situation where I am sending data to a Controller via jQuery $.ajax, the data is a serialized json string. (MVC 3.0) It binds it fine - my controller receives the results and they are ...

Knockout.js and MVC

Just started playing with knockout.Js which is a fantastic framework Steve s really done well with that one. One thing I can t seem to do at the minute is impliment it with my Html Helpers. So for ...

Anyone using Knockoutjs with asp.net-mvc in anger? [closed]

I find it very interesting and have a prototype working based on Steve s mvc sample and another small sample from this thread. Using json.net to deserialize within the post action as I couldn t ...

热门标签