문제

컨트롤러 함수에서 동기화 된 여러 개의 찾기 쿼리를 구현하려고합니다. jquery.js는 Gruntfile에서 ** / * 이전에 배치됩니다.나는 돛을 v0.9.4로 사용합니다. 첫 번째 오류 :

"$ is not defined"
.

여기에서 발생합니다 :

var dfd = $.Deferred();
.

JS와 비교적 새로운 항해에 대한 새로운 연구와 그 질문에 대한 꽤 오랜 연구가 절대적으로 가난했습니다.

미리 감사드립니다. 마틴

추신 : Gruntfile 발췌 :

var jsFilesToInject = [
'linker/js/socket.io.js',
'linker/js/sails.io.js',
'linker/js/app.js',
'linker/js/jquery.js',
'linker/js/jquery.validate.min.js',
'linker/**/*.js'
];
.

컨트롤러 발췌 :

var dfds = [];
var seriesLists = [];

function checkForWord(word,place) {
  var dfd = $.Deferred();
  Series.find({seriesname:{'contains':'word'}}, function (err,sers) {
    seriesLists[place] = sers;
    dfd.resolve();
  });
  return dfd.promise();
}

for(var k=0;k<words.length;k++) {
  dfds.push(checkForWord(words[k],k));
}

$.when.apply($, dfds).then(function() {
  console.log("seriesLists:",seriesLists);
});

}
.

도움이 되었습니까?

해결책

사용자를 고려해야합니다.

  1. 컨트롤러는 sailsjs 측면에 살고 있습니다. 즉, 서버 (노드 js) 측면에 있습니다.
  2. 그 립 파일은 jQuery 라이브러리를 클라이언트 (브라우저) 측에서 해석 될 HTML에 주입합니다.
  3. 컨트롤러가 jQuery 라이브러리를 볼 수없는 이유입니다.서버 측에 jQuery를 가지고 싶으면 (어떻게 든 홀수를 찾으십시오) npm :

    npm install jquery
    
    .

    또는 더 적절한 :

    npm install node-query
    
    .

    어쨌든, 당신이 찾고있는 것이 약속을지지한다면, Q (클라이언트 측 또는 서버 측에 대해 가장 많이 사용되는 약속 라이브러리 중 하나 인 경우)를 사용할 수 있습니다.서버 측면에서 다음과 같이 q를 설치할 수 있습니다.

    npm install q
    
    .

    (물론 나는 완전히 틀리지 않고 "클라이언트 측"컨트롤러를하고 있는지 않는 한,)

다른 팁

머리 섹션에서 jQuery를 포함하는 순서를 확인하십시오.

페이지에 한 번 포함되어 있는지 확인하십시오.

var dfd = $.Deferred();
.

돛에 버전 0.11 jQuery로드 부트 스트랩 후 jQuery를 먼저 넣고 오류가 나타나지 않아 부트 스트랩이 올바르게 작동하기 전에 jQuery를로드해야합니다

돛의 태스크 / pipeline.js 에서이 경로로 이동하여 var JSFileStoInject= [- -here-]의 jquery-.js의 jquery-.js의 jquery-.js를 'js 사이에 넣어야합니다./dependencies/sails.io.js '및'js / dependencies / ** / *. js '는 다음과 같습니다 :

// Client-side javascript files to inject in order
// (uses Grunt-style wildcard/glob/splat expressions)
var jsFilesToInject = [

  // Load sails.io before everything else
  'js/dependencies/sails.io.js',
  //For make your jquery load first
  'js/dependencies/jquery-2.1.1.js',

  // Dependencies like jQuery, or Angular are brought in here
  'js/dependencies/**/*.js',

  // All of the rest of your client-side js files
  // will be injected here in no particular order.
  'js/**/*.js'
];
.

예를 들어, 이것은 나쁜 구성입니다.

var jsFilesToInject = [
'linker/js/socket.io.js',
'linker/js/sails.io.js',
'linker/js/app.js',
'linker/js/jquery.js',
'linker/js/jquery.validate.min.js',
'linker/**/*.js'
];
.

jQuery가 app.js보다 뒤에로드되므로 앱에서 jQuery 함수를 사용하면

에 오류가 나타납니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top