// You can also construct a button in the form, and use GetCommand to receive the contents of the cmd attribute.
var table = {
type: 'table',
title: 'position operation',
cols: ['Column1', 'Column2', 'Action'],
rows: [
['abc', 'def', {'type':'button', 'cmd': 'coverAll', 'name': 'close position'}],
]
};
LogStatus('`' + JSON.stringify(table) + '`')
// Or construct a separate button
LogStatus('`' + JSON.stringify({'type':'button', 'cmd': 'coverAll', 'name': 'close position'}) + '`')
// Button styles can be customized (bootstrap's button attributes)
LogStatus('`' + JSON.stringify({'type':'button', 'class': 'btn btn-xs btn-danger', 'cmd': 'coverAll', 'name': 'close position'}) + '`')
Dokumen API menunjukkan bahawa memaparkan jadual, rentetan, imej, carta, dan lain-lain dalam bar status strategi dicapai dengan memanggil fungsi API:
LogStatus
.Kita juga boleh menyediakan butang interaktif dengan membina data JSON.
DEMO Kod Sumber:
“
function test1(p) { Log("Calls a custom function with parameters:", p); return p; } function main() { while (true) { var table = { type: 'table', title: 'position operation', cols: ['Column1', 'Column2', 'Action'], rows: [ ['a', '1', { 'type': 'button', // To display a button, you must set the type to button. 'cmd': "CoverAll", // String, sent data, accepted by the GetCommand() function. 'name': 'close position' // The name displayed on the button. }], ['b', '1', { 'type': 'button', 'cmd': 10, // numerical value 'name': 'Send value' }], ['c', '1', { 'type': 'button', 'cmd': _D(), // The function is called for the duration of the strategy run 'name': 'call the function' }], ['d', '1', { 'type': 'button', 'cmd': 'JScode:test1("ceshi")', // String, the JS code to execute. 'name': 'Send JS Code' }] ] }; LogStatus('
+ JSON.stringify(tabel) + ` )
var str_cmd = GetCommand();
if (str_cmd) {
Log("Received Interaction Data str_cmd:", "type:", typeof(str_cmd), "value:", str_cmd);
}
if (str_cmd && str_cmd.split(':', 2)[0] == "JScode") { // Determine if there is a message
var js = str_cmd.split(':', 2)[1]; // Split the returned message string, limit it to two, and assign the element with index 1 to a variable named js.
Log("Execute debugging code:", js); // Output executed code
try { // Abnormal detection
eval(js); // Executes the eval function, which executes the parameters (code) passed in.
} catch (e) { // throw an exception
Log("Exception", e); // Output error messages
}
}
Sleep(500);
}
}
Let's run it. The strategy runs as shown:
![Constructing Interactive Button Functions in the Strategy Status Bar](/upload/asset/28d692a53d0c76776636b.png)
We can trigger the interaction by clicking on the buttons in the table on the status bar. We will click on the "Close Position" and "Send Value" buttons in turn.
When we click on the "Close Position" button, the message will be sent as normal:
![Constructing Interactive Button Functions in the Strategy Status Bar](/upload/asset/28d692a53d0c76776636b.png)
![Constructing Interactive Button Functions in the Strategy Status Bar](/upload/asset/28d4338ccfcdaf615af37.png)
Tetapi ia tidak berfungsi apabila anda mengklik pada
Send value kerana[ 'cmd': 10, // value
Ini 10. Jenis nombor tidak boleh dihantar.[Membina]Fungsi butang interaktif dalam Bar Status Strategi](/upload/asset/2d8e0f86599f1b82da792544b7b840bc824d4a96.png)
Ia telah dioptimumkan untuk serasi dengan nilai berangka, dan mengembalikan rentetan nilai.
”`
Seterusnya kita klik pada butang
Data yang diterima dicetak dalam log:
Akhirnya, mari kita klik pada
function test1(p) {
Log("Calls a custom function with parameters:", p);
return p;
}
Klik butang:
Anda boleh melihat bahawa Log ((
Calling fungsi tersuai dengan parameter: , p); pernyataan dalam fungsi ujian1 telah dilaksanakan.
Memasukkan
Mulakan latihan sekarang!