2013-10-17 63 views
0

我有一些麻煩。我使用地理服務編寫了一個Web應用程序。 有一個ViewModel thar包含一個'Queuers'的observableCollection和一個代表來自該集合的'Queue'的Propery SelectedItem。的SelectedItem的值設置表:淘汰賽js。從表中獲取元素並將其設置爲當前值。

<tbody data-bind="foreach: Queuers"> 
         <tr> 
          <td class="text-center"> 
           <span data-bind="text: Number"></span> 
          </td> 
          <td class="text-center"> 
           <i class="icon-flag icon-2x" data-bind="style: { color: Color }"></i> 
          </td> 
          <td class="text-center"> 
           <span data-bind="text: Length"></span> 
          </td> 
          <td class="text-center"> 
           <span data-bind="text: Resolution"></span> 
          </td> 
          <td class="text-center"> 
           <button style="background: none; border: none" data-bind="click: $root.getData" @*onclick="$('#myModal').modal()"*@> 
            <i class="icon-thumbs-up-alt icon-2x"></i> 
           </button> 
          </td> 
          <td class="text-center"> 
           <button style="background: none; border: none" data-bind="click: $root.remove"> 
            <i class="icon-trash icon-2x"></i> 
           </button> 
          </td> 
         </tr> 
        </tbody> 

和視圖模型:

var Query = function (number, color, length, res, data) { 

     this.Number = ko.observable(number); 
     this.Color = ko.observable(color); 
     this.Length = ko.observable(length); 
     this.Resolution = ko.observable(res); 
     this.Data = ko.observable(data); 

    }; 

    function TwoDimViewModel() { 
     var self = this; 
     self.SelectedItem = ko.observable(); 
     self.SelectedColor = ko.observable(); //just for test 
     self.Queuers = ko.observableArray(); 
     self.remove = function (q) { 
      self.Queuers.remove(q); 
     }; 
     self.getData = function (q) { 
      self.SelectedItem = q; 
      self.SelectedColor = q.Color(); //just for test 
     self.addQ = function (q) { 
      self.Queuers.push(q); 
     }; 
     self.removeAll = function() { 
      self.Queuers([]); 
     }; 
    } 

正如你看到的,有一定的邏輯與ObservaleCollection操縱。和所有工作完美期待之一:

self.getData = function (q) { 
      self.SelectedItem = q; 
    } 

我想在SelectedElement我

<div class="row" data-bind="visible: Queuers().length >= 1"> 
       <button class="btn btn-default" onclick="clearAll()">Clear all</button> 
       <br /> 
       Current selected id: <span data-bind="text: SelectedItem() ? SelectedItem().Number() : 'select element'"></span> 
       <br /> 
       Выбран цвет: <span data-bind="text: SelectedColor() ? SelectedColor: 'nulll'"></span> 
      </div> 

會有電流值。 而如何才能獲得訪問是財產(號碼,顏色等)

回答