GithubHelp home page GithubHelp logo

examples's Issues

jquery 的引用BUG?

被这个问题彻底搞困惑了,接触seajs没几天, 一直被如何引入jquery 而困扰. 我怎么感觉jquery 必须放在 jquery/jquery/1.10.1/jquery.js 才能生效呢?

目录结构很简单, 所有文件都在一个目录中, index.html, application.js, jquery.js

index.html:

<script src="sea.js" ></script>
<script>

seajs.config({
    base: "./",
    alias: {
      "jquery": "jquery.js"   // 换成"jquery/jquery/1.10.1/jquery.js", 并将jquery放入这个位置就没有问题。
    }
});
seajs.use("./application");

</script>

application.js:

define(function(require,exports,module){
var $ = require('jquery');
console.log($("#xxx").html());
});

jquery.js 来自 seajs-master example/sea-modules/jquery/jquery/1.10.1/jquery.js

错误是: TypeError: $ is not a function,
debug seajs.cache
jquery 其实已经被加载进来了。。。
但是发现还有一个 http://localhost:8080/plugins/seajs/mktry/jquery/jquery/1.10.1/jquery.js
这个就不知道从哪里来的了。。。

期待您的回复 :)

在lukcy这个应用中使用spm build的问题

spm版本2.2.12
初始情况,examples/lucky/1.0.0/main-debug.js和static/lucky/dist/main-debug.js的文件内容是一模一样的。
未作任何修改,进入到static/lucky 目录,使用spm build命令。
构建完以后,examples/lucky/1.0.0/main-debug.js和static/lucky/dist/main-debug.js的文件却已经有所不同。具体看下图。
filediff

??这是spm-build的问题??
(PS:代码原封不动从github上clone下来,未作任何修改)

require函数参数问题

刚开始学sea.js ,看了这个hello的例子,发现文档确实讲的模棱两可。比如这个例子在dev模式中static\hello\src\main.js的代码如下:

define(function(require) {
var Spinning = require('./spinning');
// var Spinning = require('./spinning.js'); //需要加.js后缀吗?
var s = new Spinning('#container');
s.render();
});

这里作为初学者,我有两点疑问:
问题1:下面的路径 ./spinning 是相对于哪里的路径?是相对于网页hello.html的路径,可是hello.html里面没有spinning.js。所以猜测:应该是相对于当前main.js的路径,表示main.js当前目录下的spinning.js
问题2:为什么var Spinning = require('./spinning'); 这里没有加后缀 .js ,我看前面的教程,这里都有过加后缀.js ,或者用seajs.config.alias 来定义一下.js的别名也行。这种例子和文档实在是不详细,应该明确说明函数 require()的参数类型是什么格式的字符串嘛: 是接字符串的js文件路径,是也可以用js文件路径的alias字符串也行,说清楚,减少初学者弯路。

我还是继续往下读文档吧。。。

别名问题

alias: {
    'jquery':'/js/lib/jquery-1.10.2.min.js'
},

请问我用这种方式配置别名,

然后var $ = require('jquery'); 这个$为null

如果直接require('jquery');就没问题

这是为什么,这跟示例不一样啊

build后的代码是这样使用吗

看了官网的hello的example,如果要使用构建后的脚本,页面上我这样使用的:
1、引入脚本
script src="static/seajs/sea.js?t=20130306
script src="static/hello/dist/main.js?t=20130306
2、添加配置和启动运行

<script type='text/javascript'> seajs.config({ plugins: ['shim'], alias: { 'jquery': { src: 'lib/jquery-1.9.1.min.js', exports: 'jQuery' } } }); seajs.use(["hello/dist/main"]); </script>

这样就可以运行了,所以对于构建或者实际的开发应用我可以这样理解吗:
如果我依赖于zepto和seajs做开发,
第一步:把seajs和zepto在保留版权的情况下压缩为一个脚本
第二步:业务逻辑依赖的所有模块通过build压缩为一个脚本
第三步:使用seajs.use(["入口模块"])

这样的话页面上js的请求数就可以变为只有两个了,不知道理解是否到位,还请点播一下,谢谢!

'spm deploy' error

按照 examples 做了个测试,build 正常,deploy 错误,望指教,thx

bogon:hello mittya$ spm deploy


           Task: "scp:assets" (scp) task
          error: error getaddrinfo ENOTFOUND
            ssh: close assets.dev.*.net
           warn: [Error: Task "scp:assets" failed.]

           Done: but with warnings.

如何将jQuery引入一个模块

一个独立的模块如何引入jQuery?
我下载这个例子测试:改变jquery文件的位置,代码中的路径也同时修改正确,控制台看到是成功加载了jquery文件的,但模块中并没有jquery对象。我哪里出错了?

require路径匹配不上的问题

Hello,刚开始学习seajs,使用require加载jquery时报TypeError: $ is not a function的错。在issue里找到了相关的一些解决办法,#12,#930,#438,试过里面的解决方法但还是没有进展~~
我使用的是spm下载下来的2.1.1版jquery库,模块id是jquery/2.1.1/jquery,

if ( typeof define === "function" && define.amd ) {
  define( "jquery/2.1.1/jquery", [], function() {
 return jQuery;  
  });
 }

seajs.config:

 seajs.config({
       base: './sea-modules/',
       alias: {
         'jquery': 'jquery/2.1.1/jquery.js'
       }
    });

因为是从spm下载的,jquery库放在sea-modules里面,按照在#879里的方法,base路径+id名称,我应该是可以用require取到的~~
另外,还有一个不解之处,我发现在FF的net里有2个jquery资源的请求,一个获取到了资源(type=js),另一个没有取到(type=plain/html),没取到的也没有报404,请问这是什么机制呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.