为什么event.keyCode不能在ng-keyup中工作?

时间:2016-05-26 20:29:03

标签: javascript html angularjs

<script language="javascript" type="text/javascript" src="/SiteAssets/test%20js/jquery-1.8.2.js"></script>
   <script language="javascript" type="text/javascript" src="/SiteAssets/JqLib/i18n/grid.locale-en.js"></script>
   <script language="javascript" type="text/javascript" src="/SiteAssets/JqLib/jquery.jqGrid.min.js"></script>
    <script language="javascript" type="text/javascript" src="/SiteAssets/JqLib/jquery.SPServices-0.7.2.min.js"></script>
   <script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/json2/20150503/json2.min.js"></script>
   
  <link rel="stylesheet" href="/SiteAssets/styles/ui.jqgrid.css">
    
  <link rel="stylesheet" href="/SiteAssets/styles/ui-lightness/jquery-ui-1.7.3.custom.css">
    
  <script language="javascript" type="text/javascript">
    $(document).ready(function() {
  debugger;
  jQuery("#list").jqGrid({
  datatype: GetMyData,
  colNames:["ID","Title","Description"],
  colModel:[{name:'ID',index:'ID',align:'left',sortable: true,width:"1500px"},
            {name:'Title',index:'Title',align:'left',sortable: true, width:"1500px"},
            {name:'Description',index:'Description',align:'left',sortable:true, width:"1500px"},],
  pager: true,
  pager: '#pager',
  pageinput: true,
  rowNum: 5,
  rowList: [5, 10, 20, 50, 100],
  sortname: 'ID',
  sortorder: "asc",
  viewrecords: true,
  autowidth: true,
  emptyrecords: "No records to view",
  loadonce: true,
  loadtext: "Loading..."
});	
jQuery("#list").jqGrid('navGrid', "#pager", { edit: false, add: false, del: false, search: true, refresh: true }); });
  function GetMyData(){
  var ex='e';
  Query="<Query><Where><Or><Contains><FieldRef Name='Title'/><Value Type='Text'>"+ex+"</Value></Contains><Contains><FieldRef Name='Description' />"+"<Value Type='Text'>"+ex+"</Value></Contains></Or></Where></Query>";
  var CAMLViewFields="<ViewFields><FieldRef Name='Title'/><FieldRef Name='Description'/> <FieldRef Name='ID'/></ViewFields>";
  GetDataOnLoad(Query, CAMLViewFields);
  }
  
 function GetDataOnLoad(Query, CAMLViewFields) {
$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "List1",
    CAMLQuery:Query,
    CAMLViewFields:CAMLViewFields ,
    completefunc: processResult
    }); 
	}

	
function processResult(xData, status) {
  var counter = 0; 
  var newJqData = "";
debugger;
  $(xData.responseXML).SPFilterNode("z:row").each(function () {
    var JqData;
    if (counter == 0) {
    JqData="{"+'"id"'+":"+'"'+$(this).attr("ows_ID")+'",'+'"cell"'+":["+'"'+$(this).attr("ows_ID")+'",'+ '"'+$(this).attr("ows_Title")+'",'+ '"'
+$(this).attr("ows_Description")+'"'+"]}";
      newJqData = newJqData + JqData;
      counter = counter + 1;
    } else {
      	var JqData="{"+'"id"'+":"+'"'+$(this).attr("ows_ID")+'",'+'"cell"'+":["+'"'+$(this).attr("ows_ID")+'",'+ '"'+$(this).attr("ows_Title")+'",'
		+ '"'+$(this).attr("ows_Description")+'"'+"]}";
      newJqData = newJqData +","+ JqData;
      counter = counter + 1;
    }
  });
  FinalDataForGrid(newJqData, counter);
}
function FinalDataForGrid(jqData, resultCount) {
debugger;
  dataFromList = jqData.substring(0, jqData.length - 1);
  var currentValue = jQuery("#list").getGridParam('rowNum');
  var totalPages = Math.ceil(resultCount / currentValue);
  var PageNumber = jQuery("#list").getGridParam("page"); // Current page number selected in the selection box of the JqGrid
  newStr = "{"+'"total":'+'"'+totalPages+'",'+'"page":'+'"'+PageNumber+'",'+'"records":'+'"'+resultCount+'",'+'"rows":['+dataFromList+ "}]}";
  var thegrid = jQuery("#list")[0];
  var obj=JSON.stringify(newStr);
  thegrid.addJSONData(JSON.parse(newStr));
  }

 </script>
		
<table  id="list" width="100%" ></table>
<div id="pager" style="text-align:center;"></div>

这适用于onkeyup但不是ng-keyup ..我错过任何东西

2 个答案:

答案 0 :(得分:0)

使用Kernel.Bind<INoMultiBindingList<ITextExportService>>().ToMethod(ctx => { var services = new NoMultiBindingList<ITextExportService>(); foreach (var device in GetDevicesByEnvironment()) { var service = ctx.Kernel.Get<ITextExportService>(new ConstructorArgument("hotFolder", ctx.Kernel.Get<IHotFolderManager>( new ConstructorArgument("baseFolderPath", device.Path), new ConstructorArgument("defaultFileSearchPattern", "*.jmf")))); services.Add(service); } return services; }); 代替$event

event

Angular在模板中公开jQuery ng-keyup="if ($event.keyCode == 13) setCurrent(pagination.navigatevalue);" 对象,请参阅doc

答案 1 :(得分:0)

Event object is available as $event in ng event directives expressions. Another problem with your code is that you can't use control statements,例如if-else。简单的解决方案是使用逻辑AND operator &&

您的代码如下所示:

ng-keyup="$event.keyCode == 13 && setCurrent(pagination.navigatevalue)"