【发布时间】:2016-12-16 22:33:39
【问题描述】:
我正在使用带有 AngularJS 1.x 的 Kendo UI。我还将 Firebase 与 AngularFire 库一起使用。因为我使用的是 Firebase,所以我决定扩展我命名为 kendo.data.FirebaseDataSource.js 的 Kendo UI 数据源。
我的自定义 DataSource 扩展了 Kendo UI DataSource 并在我想访问 AngularFire 的功能的地方添加了自定义传输。
例如,在kendo.data.FirebaseDataSource.js 源中,我想访问 AngularFire 的 $firebaseArray 功能以及我创建的任何其他模块(实用程序等),它们驻留在另一个名为 my-custom-module.js 的文件中,但我遇到了问题看看我怎么能这样做。
我尝试执行以下操作,但它(显然)不起作用:
(function ($, kendo, firebase, $firebaseArray) {
'use strict';
编辑
kendo.data.FirebaseDataSource.js
(function ($, kendo, firebase, $firebaseArray) {
'use strict';
var getCustomer = function () {
var data = $firebaseArray(firebaseDataService.data);
var listed = [];
data.$loaded()
.then(function(){
angular.forEach(data, function(data){
listed.push({
"firstName": data.firstName,
"lastName": data.lastName
})
})
})
return listed;
};
var firebaseTransports = {
read: function (options) {
var customers = getCustomers();
options.success(customers);
}
};
kendo.data.extensions.FirebaseDataSource = kendo.data.DataSource.extend({
init: function (options) {
kendo.data.DataSource.fn.init.call(this, $.extend(true, {}, { transport: firebaseTransports }, options));
}
});
})($, kendo, firebase, $firebaseArray);
编辑 2
controllerGrid.js
var fbDataSource = new kendo.data.extensions.FirebaseDataSource({
schema: {
model: {
id: "id",
fields: {
firstName: { type: "string" },
lastName: { type: "string" }
}
}
}
})
vm.gridOptions = {
dataSource: fbDataSource
基于上述controllerGrid.js 源,我所要做的就是让我的Kendo UI Grid 小部件使用kendo.data.FirebaseDataSource.js 的读取传输功能,只需简单引用我的gridOptions 中新创建的fbDataSource。
【问题讨论】:
-
能否分享fiddle或代码sn-p,这将有助于解决问题。
-
@Shrinath 添加了一些来源。
标签: javascript angularjs firebase kendo-ui angularfire