Angularize средство выбора таксономии на стороне клиента SharePoint

Команда Patterns and Practices выпустила средство выбора таксономии на стороне клиента для использования при интеграции с SharePoint. Он работает хорошо, но использует jQuery, а мое приложение SharePoint построено на Angular... что, похоже, является растущей тенденцией. Я хотел бы использовать средство выбора таксономии на стороне клиента в Angular и не знал, как лучше всего этого добиться. Вот ссылка на компонент: https://github.com/OfficeDev/PnP/tree/dev/Components/Core.TaxonomyPicker

Я думаю, что это будет директива или есть недирективный способ замены (ака, как Angular управляет заменой/инициализацией), как они делают здесь:

HTML:

<input type="hidden" id="taxPickerGeography" />

Функция jQuery, которая получает текущий контекст и создает средство выбора таксономии

$(document).ready(function () {
    var context;

    context = SP.ClientContext.get_current();

    $('#taxPickerGeography').taxpicker({
        isMulti: false,
        allowFillIn: false,
        termSetId: '89206cf2-bfe9-4613-9575-2ff5444d1999'
    }, context);
});

Мне не нужны компоненты загрузки сценариев, как показано в примере, предоставленном командой PnP, поскольку они уже встроены в мое приложение.


person Kode    schedule 14.05.2015    source источник


Ответы (1)


Учитывая проблемы создания «отзывчивого» поля управляемых метаданных, я создал следующее, используя объектную модель JavaScript, для извлечения терминов, а затем передаю их для использования в массиве. Это включает в себя получение синонимов.

// Query Term Store and get terms for use in Managed Metadata picker stored in an array named "termsArray".

var termsArray = [];

    function execOperation() {

        // Current Context
        var context = SP.ClientContext.get_current();
        // Current Taxonomy Session
        var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
        // Term Stores
        var termStores = taxSession.get_termStores();
        // Name of the Term Store from which to get the Terms. Note, that if you receive the following error "Specified argument was out of the range of valid values. Parameter name: index", you may need to check the term store name under Term Store Management to ensure it was not changed by Microsoft
        var termStore = termStores.getByName("TermStoreName");
        // GUID of Term Set from which to get the Terms
        var termSet = termStore.getTermSet("TermSetGUIDHere");
        var terms = termSet.getAllTerms();
        context.load(terms);
        context.executeQueryAsync(function () {

            var termEnumerator = terms.getEnumerator();
            while (termEnumerator.moveNext()) {
                var currentTerm = termEnumerator.get_current();
                var guid = currentTerm.get_id();
                var guidString = guid.toString();
                var termLabel = currentTerm.get_name();

                // Get labels (synonyms) for each term and push values to array
                getLabels(guid, guidString, termLabel);
            }

            // Set $scope to terms array
            $scope.$apply(function () {
                $scope.termsArray = termsArray;
            });

        }, function (sender, args) {
            console.log(args.get_message());
        });

        // Get labels (synonyms) for each term and push values to array
        function getLabels(termguid, guidString, termLabel) {
            var clientContext = SP.ClientContext.get_current();
            var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(clientContext);
            var termStores = taxSession.get_termStores();
            // The name of the term store. Note, that if you receive the following error "Specified argument was out of the range of valid values. Parameter name: index", you may need to check the term store name under Term Store Management to ensure it was not changed by Microsoft
            var termStore = termStores.getByName("TermStoreName");
            // GUID of Term Set from which to get the Terms
            var termSet = termStore.getTermSet("TermSetGUIDHere");
            var term = termSet.getTerm(termguid);
            var labelColl = term.getAllLabels(1033);

            clientContext.load(labelColl);
            clientContext.executeQueryAsync(function () {
                var labelEnumerator = labelColl.getEnumerator();
                var synonyms = "";
                while (labelEnumerator.moveNext()) {
                    var label = labelEnumerator.get_current();
                    var value = label.get_value();
                    synonyms += value + " | ";
                }
                termsArray.push({
                    termName: termLabel,
                    termGUID: guidString,
                    termSynonyms: synonyms
                });

            }, function (sender, args) {
                console.log(args.get_message());
            });
        }
    };

    // Execute function
    execOperation();
person Kode    schedule 10.06.2015