2013-12-16 77 views
0

我是Kendo UI的新手,我想使用MVVM模式綁定kendo ui網格,並且我的數據源是sharepoint列表。所以我通過CSOM JavaScript代碼調用了SharePoint列表數據。我嘗試了不同的解決方案,但似乎沒有工作。我從sharepoint列表收集數據。Kendo UI網格數據綁定使用mvvm模式

var divisionListData = []; 
//var divisionsViewModel; 

var viewModel = kendo.observable({ 
    isVisible: true, 
    onSave: function (e) { 
     alert('hi'); 
     kendoConsole.log("event :: save(" + kendo.stringify(e.values, null, 4) + ")"); 
    }, 
    divisions: new kendo.data.DataSource({ 
     // schema: { 
      data: divisionListData, 
      schema: { 
       data: "rows", 
       model: { 
        fields: 
            { 
             ID: { type: "string" }, 
             DivisionName: { type: "string" }, 
             DivisionCode: { type: "string" }, 
             OpenDate: { type: "datetime" }, 
             CloseDate: { type: "datetime" }, 
             Description: { type: "string" }, 
            } 
       } 
      }, 
    batch: true, 
     transport: { 

      read: function (e) { 
       return divisionListData; 
      } 
}) 
}) 

function ReadList() { 
    //this.set("isDisabled", false); 
    var clientContext = new SP.ClientContext.get_current(); 
    // denote that we will be performing operations on the current web 
    var web = clientContext.get_web(); 
    // denote that we will be querying the "Business Divisions" custom SharePoint list 
    var divisionsList = web.get_lists().getByTitle("Divisions"); 
    // create a CAML query (blank means just return all items) 
    var camlQuery = new SP.CamlQuery(); 
    // denote that the operation we want to perform is getItems() on the list 
    var divisionsListItems = divisionsList.getItems(camlQuery); 
    var fields = 'Include(ID,DivisionCode, DivisionName, OpenDate, CloseDate, Description)'; 
    clientContext.load(divisionsListItems, fields); 
    clientContext.executeQueryAsync(function() { 
     // get the list item enumerator 
     var listItemEnumerator = divisionsListItems.getEnumerator(); 

     // loop through the items in our custom 
     // "Divisions" SharePoint list 
     var listItem; 

     while (listItemEnumerator.moveNext()) { 
      var division = new Division(); 
      // get the list item we are on 
      listItem = listItemEnumerator.get_current(); 

      // get the divisions 
      division.ID = listItem.get_item("ID"); 
      // var lookup_DivisionCode = listItem.get_item("DivisionCode").get_lookupValue(); 
      //lookup_DivisionCode.get_l 
      var divisionLookupField = new SP.FieldLookupValue(); 
      divisionLookupField = listItem.get_item("DivisionCode"); 
      //var test = divisionLookupField.$2d_1; 
      if (divisionLookupField != null) 
       division.DivisionCode = divisionLookupField.$2d_1; 
      division.DivisionName = listItem.get_item("DivisionName"); 
      division.Description = listItem.get_item("Description"); 
      division.OpenDate = listItem.get_item("OpenDate"); 
      division.CloseDate = listItem.get_item("CloseDate"); 
      divisionListData.push(division); 
      kendo.bind($("body"), viewModel); 
     } 

    }) 
} 
+1

請提供您已經嘗試什麼樣的代碼和一些特定的錯誤。這將使人們能夠更好地幫助你 – geedubb

+0

將SCOM放在一邊,首先使用靜態數據,一旦你獲得了mvvm的工作,進一步發展。 – Vojtiik

回答

0

你是相當接近,而不是返回讀取裏面的數組:功能(E),你需要調用

e.success(yourArrayOfData);