2

我正在尝试使用 Salesforce 的 sforce 库向 salesforce 发出 Ajax 调用。这是正在运行的示例 javascript:

function setupPage() {

    var state = { //state that you need when the callback is called
        output : document.getElementById("output"),
        startTime : new Date().getTime()};

    var callback = {
        //call layoutResult if the request is successful
        onSuccess: layoutResults,
        //call queryFailed if the api request fails
        onFailure: queryFailed,
        source: state};

    sforce.connection.query(
            "Select Id, Name, Industry From Account order by Industry",
            callback);
}
function queryFailed(error, source) {
    // not shown function code
}

function layoutResults(queryResult, source) {
   // not shown function code
}

这是我的飞镖实现:

import 'dart:html';
import 'package:js/js.dart' as js;
import 'dart:json';

void main() {

  js.scoped(() {

    var sforce = js.context.sforce;

    var callbackSuccess = new js.Callback.once(success);
    var callbackFailed = new js.Callback.once(failure);

    var sfdc = new js.Proxy(sforce.connection.query("Select Id, Name, Industry From Account order by Industry"),
        js.map({"onSuccess" : callbackSuccess, "onFailure" : callbackFailed}));    

  });
}

void success(queryResult) {
  print("queryResult is: " + queryResult);
}

void failure(error) {
  print("error is: " + error);
}

正在放置 Ajax 调用,因为我看到正在发出 POST 请求并返回数据。但是,我似乎总是收到此错误(并且我尝试了无数不同的组合):

Uncaught TypeError: object is not a function (program):370
construct (program):370
ReceivePortSync.dispatchCall darttest:178
$$._JsSendPortSync.callSync$1 minidartjs:4929
$.Proxy_Proxy$withArgList minidartjs:8194
$.Proxy_Proxy minidartjs:8183
$$.main_anon.call$0 minidartjs:6057
$.scoped minidartjs:8136
$.main minidartjs:8066
$$._IsolateContext.eval$1 minidartjs:276
$.startRootIsolate minidartjs:6533
(anonymous function)

任何帮助将不胜感激,因为我现在不知道该转向哪里。

4

1 回答 1

2

js.Proxy您收到此错误是因为您尝试sfdc使用sforce.connection.query(...). 使用的时候new js.Proxy(f)f一定是js.Proxy一个js的function。在这里你得到一个object,这就是你得到错误的原因。

这是应该工作的代码。

import 'dart:html';
import 'package:js/js.dart' as js;
import 'dart:json';

void main() {

  js.scoped(() {

    var sforce = js.context.sforce;

    var callbackSuccess = new js.Callback.once(success);
    var callbackFailed = new js.Callback.once(failure);

    sforce.connection.query("Select Id, Name, Industry From Account order by Industry",
        js.map({"onSuccess" : callbackSuccess, "onFailure" : callbackFailed}));

  });
}

void success(queryResult, source) {
  print("queryResult is: " + queryResult);
}

void failure(error, source) {
  print("error is: " + error);
}
于 2013-03-27T19:06:28.003 回答