我只是想从一个微风.js 查询中返回一个可观察的数组。
问题
如果我想使用 typescript 中的方法调用来调用它,我如何将来自微风 js 查询的数据作为 onservable 数组返回。详情:函数getAllFileStructures(callback) 没有返回promise中的observable数组数据。我想用微风调用一个查询并取回数据。我创建了 testgetAllFileStructures 来展示我想要 getAllFileStructures 做什么。
testgetAllFileStructures 返回以下内容
HTML
<script src="~/Scripts/Custom/filerepo/filestructure.DataContext.js"></script>
<script>
function load() {
var SimpleListModel2 = function () {
var DbCtx = new DataContext.FileStructure("breeze/FileRepoBreeze/");
this.items = DbCtx.testgetAllFileStructures();
//in a perfect world i would be able to change this to getAllFileStructures() and it will //just work.
}.bind(this); // Ensure that "this" is always this view model
ko.applyBindings(new SimpleListModel2(), document.getElementById("test"));
}
window.onload = load;
</script>
<div id="test">
<select multiple="multiple" data-bind="options: items"> </select>
</div>
打字稿文件
module DataContext {
export class FileStructure {
private EntityQuery: breeze.EntityQuery;
private Manager: breeze.EntityManager;
constructor(MainController: string) {
//validate the format api/BreezeController/
this.EntityQuery = new breeze.EntityQuery;
this.Manager = this.configureBreezeManager('breeze/FileRepoBreeze/');
}
private configureBreezeManager(MainController: string) {
breeze.NamingConvention.camelCase.setAsDefault();
return new breeze.EntityManager(MainController);
}
public getAllFileStructures(callback) {
//define the query
var query =
this.EntityQuery
.from('GetAllFiles')
.using(this.Manager).execute()
.then(function (data) {
return callback(data);
})
.fail(this.queryFailed);
}
public testgetAllFileStructures (){
var myObservableArray = ko.observableArray();
myObservableArray.push('Some TEST');
return myObservableArray;
}
public queryFailed(error) {
alert(error);
}
}
}