Ember Data和Northwind OData [英] Ember Data and Northwind OData

查看:125
本文介绍了Ember Data和Northwind OData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用Ember-Data b3 +来处理这样的服务, http:/ /services.odata.org/V2/Northwind/Northwind.svc 的。如果是的话,任何人都可以提供一个如何使用它来阅读OData的例子。



例如,一个JSBin显示客户列表项目可以导航到点击的客户的订单



我认为这对于不同数据协议的开发人员来说将是一个很大的福音,包括如何连接Ember应用程序Ember-数据。



我已经用灯具完成了这一切,但是真的不能用实际的服务器数据连线。

解决方案

编辑



自从我写了这个,我已经放弃了Ember,并回到了我的SPA数据应用程序的角度。这个背后的主要原因是Ember Set ,您应该使用Ember Set来连接其所有的绑定内部结构。



不幸的是,这与大多数像Jaydata或Breeze这样的libs不兼容。至少不希望对您的实体服务进行更改/保存。



Jaydata和Breeze都使用propertyChanged属性来监视您实体的更改,Ember将使用阻止这些更改您应该使用Ember Set 错误。



我可能已经编写了一些适配器来克服这个问题,但是真的没有时间,我使用一个库Ember来使我的生活更轻松。 ..没有头痛的基础知识,如数据服务查询。



所以...我真的很喜欢Ember,但不幸的是,只要他们不增强Ember Data或者彻底改变Ember Set策略,我不能使用它!



基本上,如果您打算使用数据库(JayData,Breeze)更新后端...



不要使用EMBER!



原始



(很快!)在ember数据,并没有激动真的!对于标准REST服务来说,它似乎是有希望的,而IMHO不是WCF的例子。



我最终使用JayData为此目的,我必须说它与Ember非常好地集成。 p>

这是一个快速的代码段,让你走:

  // Instanciate Ember APP 
App = Ember.Application.create();

//告诉APP初始化,但在启动
之前等待App.deferReadiness();

//设置您的JayData Store
//Entities.EntityModel由JaySvcUtil
生成App.myStore = new Entities.EntityModel({
name:'oData' ,
oDataServiceHost:< YOUR_WCF_ENDPOINT_URL>
});

//创建路线并填充模型数据
App.IndexRoute = Ember.Route.extend({
model:function(){
// This passing toArray()承诺模型
return App.myStore.People.orderBy('it.Name')。toArray();
}
});

//当JayData Store准备就绪时,点击App
App.myStore.onReady(function(){
App.advanceReadiness();
});

Ember Route Model实际上处理了JayData给出的承诺,允许我们只传递查询。请参阅: http://emberjs.com/guides/路由/异步路由/#toc_the-router-pauses-for-promises


Could Ember-Data b3+ be used for work against a service like this, http://services.odata.org/V2/Northwind/Northwind.svc. If so, could anyone provide an example on how to use it to read OData.

For example a JSBin showing a list of customers where a customer list item can navigate to the orders of a clicked customer

I think this would be a great boon for developers working against different data protocols to wrap their heads around how to wire up an Ember application with Ember-Data.

I've done this with fixtures but just couldn't really wire it up with actual server data.

解决方案

Edit

Since I wrote this, I have abandoned Ember and fell back to angular for my SPA data apps. The main reason behind this is Ember Set which you should use for Ember to wire up all its binding internals.

Unfortunately, this is not compatible with most libs like Jaydata or Breeze. At least not when you wish to make changes/saves to your entity service.

Jaydata and Breeze both use a propertyChanged property to monitor changes to your entity and Ember will prevent these changes with a You should use Ember Set error.

I could probably have written some sort of adapter to overcome this problem but really I didn't have time and I use a library "Ember" to make my life easier... not to have headaches on basics such as Data Service Queries.

So... I really love Ember, but unfortunately as long as they dont enhance "Ember Data" or drastically change the Ember Set policy, I can't use it!

Basically, if you plan to use a data library (JayData, Breeze) to update a backend...

DON'T USE EMBER!

Original

I had a look (very quickly!) at ember-data and wasnt thrilled really! It looks promising for Standard REST service which IMHO is not WCF's case.

I ended up using JayData for that purpose and I must say it integrates very well with Ember.

here is a quick snippet to get you going:

//Instanciate the Ember APP
App = Ember.Application.create();

//Tell the APP to initialize but to wait before launching
App.deferReadiness();

//Setup your JayData Store
//Entities.EntityModel was generated by JaySvcUtil
App.myStore = new Entities.EntityModel({
    name: 'oData',
    oDataServiceHost: <YOUR_WCF_ENDPOINT_URL>
});

//Create your route and populate model data
App.IndexRoute = Ember.Route.extend({
    model: function () {
        //This passes the toArray() promise to the model
        return App.myStore.People.orderBy('it.Name').toArray();
    }
});

//When JayData Store is ready, Fire the App
App.myStore.onReady(function () {
      App.advanceReadiness();
});

Ember Route Model actually handles the promise given by JayData which allows us to just pass the query. see: http://emberjs.com/guides/routing/asynchronous-routing/#toc_the-router-pauses-for-promises

这篇关于Ember Data和Northwind OData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆