简体   繁体   English

如何使用require js将jquery库模块集成到JavaScript框架中

[英]How do you intergrate jquery library modules into your javascript framework using require js

I cloned the jquery library and tried to integrate it with my own JavaScript library without much success. 我克隆了jquery库,并尝试将其与我自己的JavaScript库集成在一起,但收效甚微。

I do not need all the jquery functionality ,hence the need to only load the relevant jquery modules with the functionality i want.I have been able to load the core module (core.js) and have successfully utilized some of the functionality, however the functionality provided is limited in that i am unable to do chaining or even do simple stuff such as html element selection.Interestingly id selectors work perfectly fine, but element creation is not working. 我不需要所有的jquery功能,因此只需要用我想要的功能加载相关的jquery模块。我已经能够加载核心模块(core.js)并成功地利用了某些功能,但是提供的功能是有限的,因为我无法执行链接,甚至无法执行诸如html元素选择之类的简单操作。有趣的是,id选择器可以很好地工作,但是元素创建不起作用。

Example code of what is working and not working. 有效和无效的示例代码。

define([
"../jquery/src/core",
"../jquery/src/selector",
],
function( 
jqcore,
jqselector
){
//this works fine
var div_element = jqcore("#mydiv");

//This does not work ,i want to understand why this is not working
var body_element = jqcore("body");

//I would like to understand why i am not able to do this or what i should do for the   code below to work
jqcore("p").append("<b>Appended text</b>");

})

I am using sizzle selector which i belive is being loaded corrently but i am not sure. 我正在使用sizzle选择器,我相信它正在正确加载,但我不确定。

Are you sure you included the sizzle selector? 确定要包含嘶嘶声选择器吗? (you claim you load it but I don't see it implemented in the code?) (您声称已加载它,但我看不到代码中实现了它?)

See documentation https://github.com/jquery/jquery (chapter modules) 参见文档https://github.com/jquery/jquery (章节模块)

I believe this paragraph describes the problem you are having: 我相信本段描述了您遇到的问题:

sizzle: The Sizzle selector engine. sizzle:Sizzle选择器引擎。 When this module is excluded, it is replaced by a rudimentary selector engine based on the browser's querySelectorAll method that does not support jQuery selector extensions or enhanced semantics. 当排除此模块时,将基于浏览器的querySelectorAll方法使用不支持jQuery选择器扩展或增强语义的基本选择器引擎替换它。 See the selector-native.js file for details. 有关详细信息,请参见selector-native.js文件。

That would explain the basic selector support. 这将解释基本的选择器支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM