How to consume OData service with Html/Javascript?

后端 未结 5 1981
感动是毒
感动是毒 2020-12-23 18:59

Our project currently uses Silverlight to consume an Odata service. This has made life pretty simple since we can just reference the OData service thus giving us generated s

5条回答
  •  鱼传尺愫
    2020-12-23 19:57

    As an alternative, you can give a shot to JayData, which has oData support - based on the supercool datajs library. It provides an abstract data access layer over several storage providers or protocols, one important of them is OData.

    The above mentioned query would look something like this

    var  source = new $data.yourOdataContext({serviceUri:"http://odata.netflix.com/v2/Catalog"});
    
    source.Titles
      .take(5)
      .forEach( function(catalog) { render(catalog); });
    

    As you might wouldn't expect this gets translated to .../Titles?$filter=5, so operations are not done on the client, even if the simple syntax might suggest.

    JayData will give you JavaScript Language Query (JSLQ) letting you query for data using the ES5 standard filter function: all with JavaScript, not knowledge of OData query syntax is required.

提交回复
热议问题