I want to get the value of a certain field of a certain card. Where is the mistake in this writing?

有懂anki插件编写的吗?我想得到 某张卡片的”英式音标“字段的值:我在 _init_.py 中写了一个简单的代码,插件是成功的,但在卡片中调用时,总是错误。

import anki

def on_get_field_value(note_id, field_name):
    """Return the value of the specified field on the given note."""
    note = anki.notes.Note(note_id)
    return note.fields[field_name]

anki.hooks.addHook("get_field_value", on_get_field_value)


var fieldValue = anki.get_field_value("1699282826487","英式音标");


1 Like

It looks like you are trying to call a Python function from JS code on the card, which doesn’t work.

You may be able to use an Anki addon such as Anki Connect to fetch this data.

1 Like

我每张卡片第一次点击按钮时遇到了错误提示:not at top of queue

var $buttonReset = $("<button id='myButtonReset'>已学</button>");


async function toOne(cidd){
	try {
			var result = await invoke("answerCards", 6, {"answers":[{"cardId":cidd,"ease":1}]});
			alert(`got list of decks: ${result}`);
	} catch (error) {

//这是Anki connect 网站提供的 javascript 方法
function invoke(action, version, params={}) {
    return new Promise((resolve, reject) => {
        var xhr = new XMLHttpRequest();
        xhr.addEventListener('error', () => reject('failed to issue request'));
        xhr.addEventListener('load', () => {
            try {
                var response = JSON.parse(xhr.responseText);
                if (Object.getOwnPropertyNames(response).length != 2) {
                    throw 'response has an unexpected number of fields';
                if (!response.hasOwnProperty('error')) {
                    throw 'response is missing required error field';
                if (!response.hasOwnProperty('result')) {
                    throw 'response is missing required result field';
                if (response.error) {
                    throw response.error;
            } catch (e) {

        xhr.open('POST', '');
        xhr.send(JSON.stringify({action, version, params}));