2016-04-01 8 views
0

WebAPIから取得したデータをバインドするKendoUIグリッドがあります 結果を剣道グリッドにバインドしようとしています。kendo viewmodelを使用してwebapiにリモートでバインドする方法

/* 
    */ 
    var viewModel = kendo.observable({ 
     transport: { 
    read: { 
     url: 'http://199.63.72.194/FusionAPI/api/Site/GetSiteDetails?siteId=64909fee-e52e-4051-8277-8ba2101e743b', 
     dataType: "json", 
     contentType: 'application/json; charset=utf-8', 
     type: "GET", 
    } 
      schema: { 
       model: { 
        fields: { 
         sitename: { 
          type: "string" 
         }, 
         address: { 
          type: "string" 
         }, 
         contact: { 
          type: "string" 
         }, 
         status: { 
          type: "string" 
         } 
        } 
       }, 
       data: "siteMaster", 
      } 
     }), 
    }); 

    $("#grid").kendoGrid({ 
     dataSource: viewModel.dtSource, 
     height: 250, 
     columns: [ 
      { 
       field: "sitename", 
       title: "Site Name" 
      }, { 
       field: "address", 
       title: "Address" 
      }, { 
       field: "contact", 
       title: "Contact" 
      }, { 
       field: "status", 
       title: "Status" 
      } 
     ], 
     pageable: true, 
     sortable:true 
}); 

以下のように私はポストマンからの応答を得るが、私はグリッドに

それを結合することができていないよしかし

<div class="grid"></div> 

剣道の基礎となるの.jsコードがあります私が間違っていると私は何が足りないのですか

+0

あなたのURL http://199.63.72.194/FusionAPI/api/Site/GetSiteDetails?siteId=64909fee-e52e-4051-8277-8ba2101e743b私は前にこれを見たことがないもの – Johncena365

+1

を返していません。使用'kendo.observable'をデータソースとして使用します。これに関するドキュメント参照を表示できませんか?私は、あなたが 'viewModel = new kendo.data.DataSource({..'とグリッドの 'dataSource:viewModel'}に変更した場合、それはうまくいくはずです) – DontVoteMeDown

+0

@ JohnCena365:それは内部リンクです。 –

答えて

0

データソースの構文が正しくありません。

Here is a link to the kendo documentation for a remote datasource using MVVM.

Here is a link to a grid example.

基本的には、あなたの構文は次のようになります。

var viewModel = kendo.observable({ 
    products: new kendo.data.DataSource({ 
     transport: {.... 

また、あなたのグリッドはデータバインド属性を指定する必要があります。たとえば、次のように

<div data-role="grid" 
    data-editable="true" 
    data-toolbar="['create', 'save']" 
    data-columns="[ 
      { 'field': 'ProductName', 'width': 270 }, 
      { 'field': 'UnitPrice' }, 
      ]" 
    data-bind="source: products, 
     visible: isVisible, 
     events: { 
      save: onSave 
     }" 
    style="height: 200px"></div> 
関連する問題