Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / HTML, JavaScript, VBScript, CSS [игнор отключен] [закрыт для гостей] / Uncaught TypeError: jQuery is not a function / 20 сообщений из 20, страница 1 из 1
01.08.2019, 12:22
    #39843999
Ролг Хупин
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
Приложение ASP.NET Core +ElectronNET

1. запускаю в VS как IISExpress - в броузере все работает
2. запускаю как приложение - пишет странные ошибки, типа
Uncaught TypeError: $ is not a function
at TreeMaintain (jsTreeIndex:126)
at jsTreeIndex:143

Я заменил $ на jQuery, получил:
Uncaught TypeError: jQuery is not a function
Заменил на вызов
var idtree2 = document.getElementById('treeview');
idtree2.jstree(...)

пишет jstree не найдена, хотя студия показывает даже подсказки какие есть вызовы и параметры.
В общем - не могу понять причину фигни.

Код: javascript
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
<script src='https://code.jquery.com/jquery-latest.js'></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/themes/default/style.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/jstree.min.js"></script>

<div id="treeview"> </div>
 <script>
 function TreeMaintain() {
            var idtree2 = document.getElementById('treeview');
            //alert('idtree2:' + idtree2);
            if (idtree2 != null) {
                //idtree2.jstree({
                $('#treeview').jstree({
                    "plugins": ["search", "wholerow"],
                    'core': {
                        'data': {
                            'url': function (node) {
                                return node.id === '#' ? "/Utility/GetRoot" : "/Utility/GetChildren/" + node.id;

                            },
                            'data': function (node) {
                                return { 'id': node.id };
                            }
                        }
                    }
                });
            }
        };
	TreeMaintain();		
 </script>		
...
Рейтинг: 0 / 0
01.08.2019, 12:25
    #39844002
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
попробуй вызвать свою функцию с задержкой
...
Рейтинг: 0 / 0
01.08.2019, 12:44
    #39844014
Ролг Хупин
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
Konst_Oneпопробуй вызвать свою функцию с задержкой

как это сделать?
...
Рейтинг: 0 / 0
01.08.2019, 12:50
    #39844019
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
...
Рейтинг: 0 / 0
01.08.2019, 12:58
    #39844023
Ролг Хупин
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
Konst_OnesetTimeout

https://learn.javascript.ru/settimeout-setinterval

сделал таймаут, не помогает, сыпется, **ка....

Код: javascript
1.
2.
3.
4.
5.
6.
7.
8.
9.
Uncaught TypeError: Cannot read property 'fn' of undefined
    at util.js:55
    at bootstrap.min.js:6
    at bootstrap.min.js:6
jsTreeIndex:154 Uncaught TypeError: jQuery is not a function
    at jsTreeIndex:154

Uncaught TypeError: jQuery(...).jstree is not a function
    at TreeMaintain (jsTreeIndex:129)
...
Рейтинг: 0 / 0
01.08.2019, 13:18
    #39844048
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
jQuery is not a function - проблема в этом скорее всего
...
Рейтинг: 0 / 0
01.08.2019, 13:22
    #39844050
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
Код: sql
1.
<script src='https://code.jquery.com/jquery-latest.js'></script>



подключи скаченный скрипт с директории своего сайта в head страницы своего layout-а (или где там ты его юзаешь) и проверь будет ли работать jquery
...
Рейтинг: 0 / 0
01.08.2019, 13:28
    #39844056
Ролг Хупин
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
Konst_One jQuery is not a function - проблема в этом скорее всего


да, это проявление, а причина х.поймёшь где, все вроде нормально. Сейчас попробую минимизнуть страницу до предела, подключить скрипт локально
...
Рейтинг: 0 / 0
01.08.2019, 13:29
    #39844059
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
...
Рейтинг: 0 / 0
01.08.2019, 13:31
    #39844061
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
Install jQuery into your project using the following command in the node command prompt :

Код: sql
1.
npm install jquery --save


Now add the following code inside a script tag (or a js file):

Код: sql
1.
<script>window.$ = window.jQuery = require('jquery');</script>


You need to simply declare the jQuery and $global variables with the value (the library itself) returned for the require method.
...
Рейтинг: 0 / 0
01.08.2019, 14:11
    #39844098
Ролг Хупин
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
Konst_OneInstall jQuery into your project using the following command in the node command prompt :

Код: sql
1.
npm install jquery --save


Now add the following code inside a script tag (or a js file):

Код: sql
1.
<script>window.$ = window.jQuery = require('jquery');</script>


You need to simply declare the jQuery and $global variables with the value (the library itself) returned for the require method.

это сделал, не помогло.
...
Рейтинг: 0 / 0
01.08.2019, 14:22
    #39844108
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
после этого скрипта

Код: sql
1.
2.
<script>window.$ = window.jQuery = require('jquery');</script>
 


по прежнему недоступна $ ?
...
Рейтинг: 0 / 0
01.08.2019, 14:24
    #39844112
Ролг Хупин
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
Такой файл получился
При запуске как приложение дает ошибку

авторUncaught TypeError: jQuery is not a function
at TreeMaintain (jsTreeIndex:51)


Это строка jQuery('#treeview').jstree({

Код: html
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
@{
    ViewData["Title"] = "jsTreeIndex";
}

@{
        Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <script src='https://code.jquery.com/jquery-latest.js'></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/themes/default/style.min.css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.8/jstree.min.js"></script>
    <script src='~/lib/bootstrap/dist/js/bootstrap.min.js'></script>
</head>
<body>
    

    

    

    <h1>HTML demo</h1>

    <div id="containerParent">
        <h1>Tree container</h1>
        <div id="container">
            <ul>
                <li data-jstree='{ "opened" : true }'>
                    Rootello node
                    <ul>
                        <li data-jstree='{ "selected" : true }'>Kind node 1</li>
                        <li>Kind node 2</li>
                        <li>Kind node 3</li>
                    </ul>
                </li>
            </ul>
        </div>
        <h1>Tree2 container</h1>
        <div id="container2"> </div>
        <h1>TreeView container</h1>
        <div id="treeview"> </div>
        <h1>Tree3 container</h1>
        <div id="container3"> </div>
    </div>

    <script>window.jQuery = window.$ = require('jquery');</script>
    <script>window.jQuery = window.$ = module.exports</script>

    <script>
        if (typeof $ == 'undefined') {
            var $ = jQuery;
        }
        //$
        function TreeMaintain(divTree) {
            var idtree2 = document.getElementById('treeview');
            //alert('idtree2:' + idtree2);
            if (idtree2 != null) {
                //idtree2.jstree({
                jQuery('#treeview').jstree({
                    "plugins": ["search", "wholerow"],
                    'core': {
                        'data': {
                            'url': function (node) {
                                return node.id === '#' ? "/Utility/GetRoot" : "/Utility/GetChildren/" + node.id;

                            },
                            'data': function (node) {
                                return { 'id': node.id };
                            }
                        }
                    }
                });
            }
        };

        setTimeout(TreeMaintain, 1000, 'treeview');

        jQuery(function () {
            $.noConflict();
            $('#container').jstree();
        });

            $(function () {
            //$('#container').jstree({
            //var idtree = document.getElementById('container');
            //alert('idtree:' + idtree);
            //if (idtree != null) {
            //  idTree.jstree({
            $('#container2').jstree({
                'core': {
                    'data': [
                        {
                            "text": "Koreshok node", "children": [
                                {
                                    "text": "Bratan node 1",
                                    "children": [
                                        { "text": "Bratan node 11" },
                                        { "text": "Bratan 21" },
                                        { "text": "Bratan node 31" }
                                    ]
                                },
                                { "text": "Bratan 2" },
                                { "text": "Bratan node 3" }
                            ]
                        }
                    ]
                }
            });
            //  }
        });
    </script>
</body>
</html>
...
Рейтинг: 0 / 0
01.08.2019, 14:27
    #39844116
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
внимательно читайте (ссылку на jquery вам не надо добавлять в head, нужно через require('./path/to/jquery') делать):
https://stackoverflow.com/a/37480521

возможно вы путь указали неправильный к бибилиотеки jquery (относительный путь внутри проекта)
...
Рейтинг: 0 / 0
01.08.2019, 15:34
    #39844167
Ролг Хупин
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
Konst_Oneвнимательно читайте (ссылку на jquery вам не надо добавлять в head, нужно через require('./path/to/jquery') делать):
https://stackoverflow.com/a/37480521

возможно вы путь указали неправильный к бибилиотеки jquery (относительный путь внутри проекта)

путь длолжен быть относительно какого фолдера?

Я убрал в хеаде, добавил внизу
Код: javascript
1.
    <script>window.$ = window.jQuery = require('~/lib/jquery/dist/jquery.min.js')</script>



у меня структура фолдеров такая:

Project
-Controllers
-Views
--test.cshtml
-wwwroot
--lib
---jquery
----dist (\jquery.min.js)
--css
---site.css
...
Рейтинг: 0 / 0
01.08.2019, 15:39
    #39844176
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
wwwroot
...
Рейтинг: 0 / 0
01.08.2019, 15:41
    #39844178
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
так пробуйте:
Код: sql
1.
<script>window.$ = window.jQuery = require('./lib/jquery/dist/jquery.min.js')</script>
...
Рейтинг: 0 / 0
01.08.2019, 15:46
    #39844184
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
и этот скрипт нужно вставить до внедрения вендорских скриптов (бутстрап, дерево и тп)
...
Рейтинг: 0 / 0
01.08.2019, 16:47
    #39844229
Ролг Хупин
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
Konst_Oneи этот скрипт нужно вставить до внедрения вендорских скриптов (бутстрап, дерево и тп)

Это п-ц какой-то


Код: javascript
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
Uncaught TypeError: Cannot read property 'fn' of undefined
    at util.js:55
    at bootstrap.min.js:6
    at bootstrap.min.js:6
internal/modules/cjs/loader.js:686 Uncaught Error: Cannot find module './lib/jquery/dist/jquery.min.js'
Require stack:
- E:\MyProjects\_CrossPlatform\DbManager\DbManager\obj\Host\node_modules\electron\dist\resources\electron.asar\renderer\init.js
    at Module._resolveFilename (internal/modules/cjs/loader.js:683)
    at Function.Module._resolveFilename (E:\MyProjects\_Cross…-search-paths.js:43)
    at Function.Module._load (internal/modules/cjs/loader.js:601)
    at Module.require (internal/modules/cjs/loader.js:739)
    at require (internal/modules/cjs/helpers.js:14)
    at jsTreeIndex:41
jsTreeIndex:44 Uncaught ReferenceError: jQuery is not defined
    at jsTreeIndex:44
...
Рейтинг: 0 / 0
01.08.2019, 16:48
    #39844230
Konst_One
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Uncaught TypeError: jQuery is not a function
сами выбрали такой , читайте доки, вот ещё совет от разработчиков

https://electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron
...
Рейтинг: 0 / 0
Форумы / HTML, JavaScript, VBScript, CSS [игнор отключен] [закрыт для гостей] / Uncaught TypeError: jQuery is not a function / 20 сообщений из 20, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]