Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/430.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用require.js+;breeze.js_Javascript_Breeze_Require - Fatal编程技术网

Javascript 使用require.js+;breeze.js

Javascript 使用require.js+;breeze.js,javascript,breeze,require,Javascript,Breeze,Require,我使用breeze.js在客户机上获取一些服务器数据,这很好。为了创建一个更模块化的应用程序,我想创建一个“数据服务”,将breeze查询的in1模块捆绑起来,作为依赖项包含在其他模块中 这是模块: define(function () { var serviceName = window.location.protocol + "//" + window.location.host + '/breeze/n0uk', // route to the Web Api controller ma

我使用breeze.js在客户机上获取一些服务器数据,这很好。为了创建一个更模块化的应用程序,我想创建一个“数据服务”,将breeze查询的in1模块捆绑起来,作为依赖项包含在其他模块中

这是模块:

define(function () {

var serviceName = window.location.protocol + "//" + window.location.host + '/breeze/n0uk', // route to the Web Api controller
manager = new breeze.EntityManager(serviceName);


function getPoster(callsign) {
    var query = breeze.EntityQuery.from('Posters').where("Callsign","==",callsign);
    return manager.executeQuery(query);
};

return {
    getPoster:getPoster
};
});
我创建了一个testmodule来测试函数:

define(["common/dataService"],function(n0uk) {
alert("home/index geladen");

n0uk.getPoster("pe1l").then(function(data) {
        alert(data.Name);
    }
);
}))


遗憾的是,没有返回任何数据。我是个新手,需要新手(js经验也不是一流的)。有人能告诉我正确的方向吗?

在您的测试模块中,您正在执行
警报(data.Name)
。breeze查询将返回一个具有名为
results
的数组属性的对象,因此您可能希望使用如下内容:

define(["common/dataService"],function(n0uk) {
alert("home/index geladen");

n0uk.getPoster("pe1l")
    .then(function(data) {
        alert(data.results.length.toString() + ' items returned');
    })
    .fail(function(reason) { alert(reason); });
});
其他尝试事项:

使用浏览器的F12工具(或visual studio)设置断点并检查查询结果

使用fiddler的“inspectors”选项卡确认api调用正在返回数据:

有关
executeQuery
方法返回的内容的更多信息,请查看此处(滚动至“executeQuery”):

thanx,这就是解决方案!警报(data.results[0].Name());是否显示正确的数据。。。