如何使用 Breeze 从 MongoHQ 获取数据?到目前为止,我已经尝试过:
this.getDataFormServer = function (formElement) {
$.ajax({
url: "https://api.mongohq.com/databases/mydataBase/collections/customers/documents?_apikey=aabbddkkddiieeoollddd33kk3",
type: "GET",
data: {},
datatype: "json",
processData: false,
contentType: "application/json; charset=utf-8",
success: function (resultSuccess) {
//alert("Success: " + JSON.stringify(resultSuccess));
console.log(resultSuccess);
},
complete: function (response) {
//alert('your datas are now saved');
},
error: function (xhr, status, error) {
console.log(status);
}
});
}
它运行良好,但现在我想对 Breeze 做同样的事情,这就是我所拥有的:
<!-- Knockout template -->
<ul data-bind="foreach: results">
<li>
<span data-bind="text:FirstName"></span>
<span data-bind="text:LastName"></span>
</li>
</ul>
从查询绑定到员工:
manager.executeQuery(breeze.EntityQuery.from("Customers"))
.then(function(data){
ko.applyBindings(data);
});
谁可以帮我这个事?谢谢。
更新:我在这里做错了什么
this.getDataFormServer = function (formElement) {
var EntityQuery = breeze.EntityQuery;
var manager = new breeze.EntityManager('https://api.mongohq.com/databases/myMongoHq/collections/customers/documents?_apikey=aelctgd3p3czwh6zx5uy&limit=4');
var getRemoteDocuments = function () {
var query = EntityQuery.from('documents');
return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
};
function querySucceeded(data) { console.log('Retrieved documents from remote data source'); }
function queryFailed(data) { console.log('Failed to retrieve documents from remote data source'); }
var getLocaldocuments = function () {
console.log("getLocals called");
var newQuery = new EntityQuery('documents');
var Documents = manager.executeQueryLocally(newQuery);
if (Documents) console.log("retrieved some cars from local cache");
else console.log("no cars retrieved from local cache");
};
getRemoteDocuments().then(getLocaldocuments);
}
在控制台中我只能看到这个:
Failed to retrieve documents from remote data source anfrageerstellen.js:222
getLocals called