gpt4 book ai didi

dart - JS-Interop:尝试使用salesforce代理

转载 作者:行者123 更新时间:2023-12-03 02:58:59 26 4
gpt4 key购买 nike

我正在尝试使用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
}

这是我的dart实现:

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)

任何帮助将不胜感激,因为我不确定此时该转向何处。

最佳答案

之所以会出现此错误,是因为您尝试使用js.Proxy的结果创建一个sfdc(sforce.connection.query(...))。使用new js.Proxy(f)时,f必须是js js.Proxyfunction。在这里,您会收到一个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);
}

关于dart - JS-Interop:尝试使用salesforce代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15663869/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com