attj
2022 年 9 月 6 日午前 8:29
1
I have the following import statement in my code (javascript side):
import Tag from "discourse/models/tag";
However, I can’t use it to retrieve a tag object by it’s name. My goal is to obtain the tag description, but I only have the name. I was expecting something similar to this:
const tagObj = Tag.find("tag_name");
const tagDesc = tagObj.description;
Does the Tag model have a similar function?
「いいね!」 1
keegan
(Keegan George)
2022 年 9 月 13 日午後 10:36
2
You can fetch tag data from the /tags.json
endpoint.
In this example I’m getting an email
tag’s description:
import { ajax } from "discourse/lib/ajax";
ajax(`/tags.json`).then(({ tags }) => {
const emailTag = tags.find((tag) => tag.name === "email");
const emailTagDesc = emailTag.description;
});
「いいね!」 4
attj
2022 年 9 月 17 日午前 10:04
3
Thanks! I guess I found a more efficient way to accomplish this:
this.store.find("tag-info", "email").then(data => {
const tag_desc = data.description
});
However, I don’t know if this.store.find
is faster than sending an ajax query to all tags and filtering. Maybe it’s doing the same thing.
「いいね!」 2