2014-07-26 107 views
0

嵌套不工作当我使用以下命令:功能角度JS

$scope.test = function() { 
     this.batchId = false; 
     this.batchToggle = true; 
    } 

批次ID工程和NG-显示和鼠标悬停事件发生和作品。 $ scope.test函数显示每个批处理ID上的upload.view。

但是,当我使用这个:

$scope.searchFeature = { 
    showSearch: false, 
      addBatchButton: true, 
      test:function() { 
       // alert(this);  
       this.batchId = false; 
       this.batchToggle = true; 
      } 

showSearch.test()不起作用。并且不显示批次标识上传/查看悬停为什么?

See plunker code.

回答

0

其工作。检查this plunker

你需要改变通话ng-mouseover="searchFeature.test()"

的功能测试()的searchFeature对象内部定义,您需要使用searchFeature访问它。

它的JavaScript和工作无关与角度的方式......

编辑

结帐updated plunker,它的工作..我不得不做一些修改是...让我知道,如果其工作如期

+0

市右垣九HarishR我用searchFeature.test(),但它不工作,你可以看到,当我们使用 $ scope.test其作用是显示在每个批次ID upload.view 但是当我们使用searchFeature.test()没有变化再次出现在batchId 看到plunker http://plnkr.co/edit/gklQvFUUvx4maIczOUA2 – SamiMalik

+0

结帐[新plunker]( http://plnkr.co/edit/ylaA08iV760MVS5WzYQn?p=preview) – harishr

+0

只有小问题当鼠标悬停事件发生时,Batchid没有隐藏 我的意思是在屏幕上显示upload/view时,应该隐藏batchId。 – SamiMalik

0

试试这个。希望这是你的功能之后:

<td data-title="'ID'" ng-mouseover="test(batch)" ng-mouseleave="testLeave(batch)"> 
      <div ng-show="batch.showId">{{batch.id}}</div> 
      <div ng-show="batch.toggle"> 
      <a>Upload</a> <a ng-href="/batches/{{batch.id}}">View</a> 
      </div> 
     </td> 

    $scope.test = function (batch) { 
     batch.showId = false; 
     batch.toggle = true; 
    } 

    $scope.testLeave = function (batch) { 
     batch.showId = true; 
     batch.toggle = false; 
    } 


$scope.batches = [ 
     {id: "2014BATCH50", status: "QC in Progress. Illumina: 24/50", date: "10/24/14", qlty: "check", illumina: "none, raw, modified, modified", FX: "modified", showId: true, toggle: false}, 
     {id: "2014BATCH49", status: "Pre-Extraction", date: "10/24/14", qlty: "check", illumina: "none, raw, modified, modified", FX: "modified", showId: true, toggle: false} 

    ]; 

我减少了批次的数量只是为了提高速度。分配一个showIdtoggle属性到每个批次并直接对它们进行处理。您可以折叠此为$ scope.searchFeature结构也一样,如果你喜欢:

$scope.searchFeature = { 
     showSearch: false, 
     addBatchButton: true, 
     test:function(batch) {  
      batch.showId = false; 
      batch.toggle = true; 
     } 
    } 
+0

是的,但我需要 $ scope.searchFeature.test()它不能正常工作,如 $ scope.test();正常工作 – SamiMalik

+0

我想我现在明白了。看到我编辑的答案 – TrazeK