2016-03-24 25 views
0

私は、Authorsに基づいて単語をソートするプログラムを持っています。これは配列です。私はコンソールで$ parse:syntaxエラーを受け取っています。しかし、プログラムは実行して正しい結果を返します。私はこの問題を引き起こしているのか分かりません。私はタグや書籍のような他の属性を使って単語をソートしています。ただし、このコンソールエラーは、これらのアレイの一部のインスタンスによってのみ表示されます。

これは、それがどのように見えるかです: view

次のようにエラーがある:

angular.js:13236 Error: [$parse:syntax] Syntax Error: Token 'Baggins' is an unexpected token at column 7 of the expression [Frodo Baggins] starting at [Baggins]. 
http://errors.angularjs.org/1.5.0/$parse/syntax?p0=Baggins&p1=is%20an%20unexpected%20token&p2=7&p3=Frodo%20Baggins&p4=Baggins 
    at http://localhost:8080/node_modules/angular/angular.js:68:12 
    at Object.AST.throwError (http://localhost:8080/node_modules/angular/angular.js:13816:11) 
    at Object.AST.ast (http://localhost:8080/node_modules/angular/angular.js:13586:12) 
    at Object.ASTCompiler.compile (http://localhost:8080/node_modules/angular/angular.js:14040:31) 
    at Parser.parse (http://localhost:8080/node_modules/angular/angular.js:14927:29) 
    at $parse (http://localhost:8080/node_modules/angular/angular.js:15035:39) 
    at http://localhost:8080/node_modules/angular/angular.js:20463:17 
    at Array.map (native) 
    at processPredicates (http://localhost:8080/node_modules/angular/angular.js:20452:26) 
    at http://localhost:8080/node_modules/angular/angular.js:20416:22(anonymous function) @ angular.js:13236(anonymous function) @ angular.js:9965Scope.$digest @ angular.js:16682Scope.$apply @ angular.js:16928clickListener @ angular-material.js:14066defaultHandlerWrapper @ angular.js:3398eventHandler @ angular.js:3386 
angular.js:13236 Error: [$parse:syntax] Syntax Error: Token 'Baggins' is an unexpected token at column 7 of the expression [Frodo Baggins] starting at [Baggins]. 
http://errors.angularjs.org/1.5.0/$parse/syntax?p0=Baggins&p1=is%20an%20unexpected%20token&p2=7&p3=Frodo%20Baggins&p4=Baggins 
    at http://localhost:8080/node_modules/angular/angular.js:68:12 
    at Object.AST.throwError (http://localhost:8080/node_modules/angular/angular.js:13816:11) 
    at Object.AST.ast (http://localhost:8080/node_modules/angular/angular.js:13586:12) 
    at Object.ASTCompiler.compile (http://localhost:8080/node_modules/angular/angular.js:14040:31) 
    at Parser.parse (http://localhost:8080/node_modules/angular/angular.js:14927:29) 
    at $parse (http://localhost:8080/node_modules/angular/angular.js:15035:39) 
    at http://localhost:8080/node_modules/angular/angular.js:20463:17 
    at Array.map (native) 
    at processPredicates (http://localhost:8080/node_modules/angular/angular.js:20452:26) 
    at http://localhost:8080/node_modules/angular/angular.js:20416:22(anonymous function) @ angular.js:13236(anonymous function) @ angular.js:9965Scope.$digest @ angular.js:16682processQueue @ angular-material.js:1316(anonymous function) @ angular.js:18744completeOutstandingRequest @ angular.js:5804(anonymous function) @ angular.js:6081 

ビューで

{ 
"expression": "to the day", 
"meaning": "", 
"example": "it's been four years to the day.", 
"pronunciation": "", 
"notes": "", 
"meta": { 
"book": ["There and back again"], 
"author": ["Frodo Baggins"], 
"tags": ["middle earth"]} 
}, 

コードを次のようにJSONは次のとおりです。

<md-input-container> 
     <label>Books</label> 
     <md-select ng-model="book"> 
      <md-option ng-repeat="book in books | orderBy: book" value="{{ book }}"> <!-- books here refers to a newly defined array that stores only one instance of all the books against the 'book' property on each object/word --> 
       {{ book }} 
      </md-option> 
     </md-select> 
    </md-input-container> 
次のように

コントローラのコードは次のとおりです。

function getBooks(classifieds) { 

     var books = []; 
     angular.forEach(classifieds, function(item) { 
      if (item.meta) {  
       angular.forEach(item.meta.book, function(b) { 

        books.push(b); 
       }); 
      } 

     }); 

     return _.uniq(books); 

    } 
+0

Chromeをインストールし、それをあなたのページを試してみてください。あなたはエラーをクリックすることができますデバッグでは、それは角ウェブサイト上のページを開きます。このページは少しエラーを説明します – AlainIb

+1

完全なJSコード –

+0

'$ scope.books = getBooks(クラシファイド);を書いてくださいこれは上記のgetBooks関数を呼び出します – Nosail

答えて

0

簡単な答えは私が考える - お読みください順:| orderBy:'book' https://docs.angularjs.org/api/ng/filter/orderBy

+0

oh yes ..私は引用符でそれを追加しました。 "実行時エラーはありません。ただし、タグ配列の値はアルファベット順でソートされていません。不思議なことに、私は引用符でそれを追加する前でした。 – Nosail

+0

本は引用符に含まれていません - 私は前述のランタイムエラーを受け取りました。しかし、その値はブックリストのアルファベット順にソートされています。私は上記のランタイムエラーを取得していません。ただし、値はアルファベット順に並び替えられていません。 – Nosail

+0

私の最初のコメントは私が言った意味ですが、BOOK配列(タグではない)の値はアルファベット順に並び替えられていません。不思議なことに、私は引用符でそれを追加する前でした。 – Nosail

関連する問題