2013-10-04 98 views
0

這是我如何我的頁面設置,但顯示沒有數據,我不知道爲什麼:數據綁定在視圖頁面不顯示數據

的JavaScript /淘汰賽:

var getList = function() { 
      Ajax.Get({ 
       Url: ..., 
       DataToSubmit: {id: properties.Id }, 
       DataType: "json", 
       OnSuccess: function (roleData, status, jqXHR) { 
        bindModel(roleData); 

       } 
      }); 
     }; 


    // Binds the main ViewModel 
     var bindModel = function (data) { 
      var _self = viewModel; 

      ko.applyBindings(viewModel, $('#ListView')[0]); 
     }; 

    var viewModel = { 
      ListRoleTypes: ko.observableArray([]), 
      ..... 
     }; 

var roleViewModel = function (data) { 
     var _self = this; 
     _self.ContentRole = ko.observable(data.ContentRole); 
     _self.RoleName = ko.observable(data.RoleName); 
     _self.RoleRank = ko.observable(data.RoleRank); 
     _self.UserCount = ko.observable(data.UserCount); 
    }; 

這是我的看法頁:

<div data-bind="foreach: ListRoleTypes"> 
      <span data-bind="text: RoleName"></span> 
     </div> 

在哪裏我錯了有什麼想法?

回答

2

您正在調用bindmodel並傳入roledata,但隨後在bindmodel中,您不會對其執行任何操作。

Ajax.Get({ 
      Url: ..., 
      DataToSubmit: {id: properties.Id }, 
      DataType: "json", 
      OnSuccess: function (roleData, status, jqXHR) { 
       bindModel(roleData); 

      } 
     }); 
    }; 


// Binds the main ViewModel 
    var bindModel = function (data) { 
     // need to do something with viewmodel to handle the passed in data 
     viewmodel.initialize(data); 

     ko.applyBindings(viewModel, $('#ListView')[0]); 
    }; 
+0

偉大 - 我得到它去,現在我增加了一個模型,所以我有來自兩個不同模型的數據,我想創建一個foreach循環中,我將有一個外環(listRoleTypes)和內環將是用戶,以便我將列出每個列表角色類型的用戶 – Masriyah

相關問題