在本文中,我们将给您介绍关于JS条件添加到对象数组在React应用程序中给出了错误的结果的详细内容,并且为您解答js添加对象到数组方法的相关问题,此外,我们还将为您提供关于angularjs–如何在不
在本文中,我们将给您介绍关于JS 条件添加到对象数组在 React 应用程序中给出了错误的结果的详细内容,并且为您解答js添加对象到数组方法的相关问题,此外,我们还将为您提供关于angularjs – 如何在不使用require.js的情况下启动应用程序后,将模块添加到应用程序中?、delphi – TOSVersion给出了错误的结果、ember.js – Ember Inspector在检查我自己的ember应用程序时给出了错误、Grep 给出错误的结果的知识。
本文目录一览:- JS 条件添加到对象数组在 React 应用程序中给出了错误的结果(js添加对象到数组方法)
- angularjs – 如何在不使用require.js的情况下启动应用程序后,将模块添加到应用程序中?
- delphi – TOSVersion给出了错误的结果
- ember.js – Ember Inspector在检查我自己的ember应用程序时给出了错误
- Grep 给出错误的结果
JS 条件添加到对象数组在 React 应用程序中给出了错误的结果(js添加对象到数组方法)
如何解决JS 条件添加到对象数组在 React 应用程序中给出了错误的结果?
在 React 应用程序中,我将此条件添加到数组中,
var flag = .. // returns TRUE or FALSE
infographicObjectsArray.push({
"buttons": [
{"id":"viewAgreementsButton","variant":"outline-" + variantType,"text":"View Agreement","url":"/viewAgreementForm?id=" + eligibleSingleAgreement.id},flag &&
{"id":"newAgreementButton","variant":variantType,"text":"New Agreement","url":"/newAgreementType"}
]
});
第二项是 false
而不是创建的对象。请注意,这是 React,因此可能还有其他东西在起作用。
解决方法
表达式
flag &&
{
"id": "newAgreementButton","variant": variantType,"text": "New Agreement","url": "/newAgreementType"
}
将返回对象或未定义,具体取决于 flag
的值。
两者都不是可迭代的,因此在这两种情况下,当您尝试对其进行迭代时(即,当您使用扩展运算符时)都会出现类型错误。
您可能想要:
var flag = .. // returns TRUE or FALSE
infographicObjectsArray.push({
"buttons": [
{id: 1},flag && {id : 2}
].filter(v => v) // filter out `undefined` if `flag` is `false`
});
angularjs – 如何在不使用require.js的情况下启动应用程序后,将模块添加到应用程序中?
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <security> <authorization> <remove users="*" roles="" verbs="" /> <add accesstype="Allow" roles="Admin" /> </authorization> </security> </system.webServer> </configuration>
所以我的服务器端解决方案似乎已经解决了.但是我完全不知道在客户端上做什么,如何下载脚本并在引导后将模块添加到我的应用程序中.这就是我所拥有的:
我使用web-config保护的admin目录中的文件如下所示:
admin.js
angular.module('admin',[])
homeController.js
angular.module('admin') .controller('AdminHomeController',['$http','$q','$resource','$scope','_o',adminHomeController]); function adminHomeController($http,$q,$resource,$scope,_o) { .... ... }
我的应用程序级文件如下所示:
app.js
var app = angular .module('app',['ui.router','admin','home',]) .run(['$rootScope','$state','$stateParams','$http','$angularCacheFactory',appRun]) function appRun($rootScope,$state,$stateParams,$http,$angularCacheFactory) { $rootScope.$state = $state; $rootScope.$stateParams = $stateParams; }
app.config.js
app.config(['$controllerProvider','$httpProvider','$locationProvider','$sceprovider','$stateProvider',appConfig]); function appConfig($httpProvider,$locationProvider,$sceprovider,$stateProvider) { // I added this to help with loading the module after // the application has already loaded app.controllerProvider = $controllerProvider; // $sceprovider.enabled(false); $locationProvider.html5Mode(true); var admin = { name: 'admin',url: '/admin',views: { 'root': { templateUrl: '/Content/app/admin/partials/home.html',},'content': { templateUrl: '/Content/app/admin/partials/overview.html',} }; var adminContent = { name: 'admin.content',parent: 'admin',url: '/:content','content': { templateUrl: function (stateParams) { return '/Content/app/admin/partials/' + stateParams.content + '.html'; },} } }; var home = { name: 'home',url: '/home',views: { 'root': { templateUrl: '/Content/app/home/partials/home.html','content': { templateUrl: '/Content/app/home/partials/overview.html',} }; var homeContent = { name: 'home.content',parent: 'home','content': { templateUrl: function (stateParams) { return '/Content/app/home/partials/' + stateParams.content + '.html'; },} } }; $stateProvider .state(admin) .state(adminContent) .state(home) .state(homeContent); }
当用户登录时,我知道它是否是Admin角色用户,因为我有一个安全令牌返回给我,显示:
{ "access_token":"abcdefg","token_type":"bearer","expires_in":1209599,"userName":"xx","roles":"Admin",".issued":"Fri,30 May 2014 12:23:53 GMT",".expires":"Fri,13 Jun 2014 12:23:53 GMT" }
如果是管理员角色用户,那么我想
>从服务器下载管理模块脚本:/Content/app/admin/admin.js和/Content/app/admin/homeController.js.我已经为$http调用设置了这个:$http.defaults.headers.common.Authorization =’Bearer’user.data.bearerToken;所以在获取脚本时需要发送Bearer令牌:
>将管理模块添加到应用程序
有人可以给我一些关于如何做这两件事的建议.在阅读了关于require.js之后,我觉得我不想用它作为解决方案.我希望尽可能简单.
根据我的理解,直到AngularJS允许它,然后我需要做它,以便我可以注入我的控制器.所以我已经将它添加到appConfig:
app.controllerProvider = $controllerProvider;
但是如何下载这两个javascript文件以及如何将这些文件添加到AngularJS中以便用户可以开始使用管理模块中的控制器功能?我看到Angular团队正在使用$script.js.这是一个很好的解决方案,我怎么能实现这个来满足我相当简单的需求.
解决方法
var admin = { name: 'admin',resolve: { isAdminAuth: function($q,User) { var defer = $q.defer(); if (User.isAdmin) { defer.resolve(); } else { defer.reject(); } return defer.promise; } },views: { 'root': { templateUrl: '/Content/app/admin/partials/home.html','content': { templateUrl: '/Content/app/admin/partials/overview.html',} };
你也可以链接这个.
resolve: { adminPermissions: function($q,User) { var defer = $q.defer(); if (User.permissions.isAdmin) { defer.resolve(User.permissions.admin); } else { defer.reject(); } return defer.promise; },hasAccesstoHome: function($q,adminPermissions) { var defer = $q.defer(); if (adminPermissions.hasAccesstoHome) { defer.resolve(true); } else { defer.reject(); } return defer.promise; },
如果已解决,则解析属性的结果也将传递给控制器.如果被拒绝,路由将不会加载.你可以像这样访问它.
function adminHomeController($scope,adminPermissions,hasAccesstoHome) { $scope.adminPermissions = adminPermissions; }
您还可以手动引导应用程序:
<!doctype html> <html> <body> <div ng-controller="WelcomeController"> {{greeting}} </div> <script src="angular.js"></script> <script> var isAdmin = true; <!-- injected variable from server here --> var app = angular.module('demo',[]) .controller('WelcomeController',function($scope) { $scope.greeting = 'Welcome!'; }); angular.bootstrap(document,['demo']); </script> </body> </html>
[参考] – https://docs.angularjs.org/api/ng/function/angular.bootstrap
您可以使用jQuery发出请求,而不是注入变量或其他服务器端模板方法:
$.getJSON('/my/url',function(data) { if (data.isAdmin) { // bootstrap app with admin module } else { // bootstrap app without admin module } });
这是一个IE8兼容的示例替代上面(不是jQuery):
request = new XMLHttpRequest(); request.open('GET','/my/url',true); request.onreadystatechange = function() { if (this.readyState === 4){ if (this.status >= 200 && this.status < 400){ data = JSON.parse(this.responseText); if (data.isAdmin) { // bootstrap app with admin module } else { // bootstrap app without admin module } } } }; request.send(); request = null;
[参考] – http://youmightnotneedjquery.com/#json
delphi – TOSVersion给出了错误的结果
TOsversion.Name: Windows 7 TOsversion.ToString: Windows 7 Service Pack 1 (Version 6.1,Build 7601,64-bit Edition) TOsversion.Name: Windows XP TOsversion.ToString: Windows XP Service Pack 3 (Version 5.1,Build 2600,64-bit Edition)
可能导致什么问题?
清单文件设置自动生成.没有.manifest文件,但我可以在两个项目的.res文件中找到“supportedOS”条目.它们都具有相同的内容,如下所示:
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> <application> <!--The ID below indicates app support for Windows Vista --> <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> <!--The ID below indicates app support for Windows 7 --> <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> <!--The ID below indicates app support for Windows 8 --> <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> <!--The ID below indicates app support for Windows 8.1 --> <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> <!--The ID below indicates app support for Windows 10 --> <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> </application> </compatibility>
解决方法
TOsversion记录使用GetVersionEx来确定其类构造函数中的OS版本,该版本由垫片作为 documented实现.
验证的一种方法是检查事件日志.将记录一个事件,即通过程序属性对话框(support article)或Program Compatibility Assistant或Application Compatibility Toolkit应用修复程序的用户.您可以搜索可执行文件的名称.
Event Log\Application and Services\Microsoft\Windows\Application-Experience\Program-Telemetry
ember.js – Ember Inspector在检查我自己的ember应用程序时给出了错误
Uncaught TypeError: Object [object Object] has no method 'highlightView' Uncaught TypeError: Cannot read property 'style' of undefined
它试图设置一些我的网站上不存在的DOM元素,但是在话语网站上.有什么想法我需要设置才能使这个工作?
解决方法
我建议更新您的依赖项并尝试latest night build
Grep 给出错误的结果
如何解决Grep 给出错误的结果?
假设我在目录 (files)
中有一些文件 (A_1.x,A_2.txt,A_3.txt)这可以正常工作:
find files/ | grep ".txt" | while read -r file ; do
echo $file
done
--> Result:
files/A_1.txt
files/A_2.txt
files/A_3.txt
但是,当我在循环中调用另一个程序时,greps 结果被修改:
find files/ | grep ".txt" | while read -r file ; do
... Other program here ...
echo $file
done
--> Result:
files/A_1.txt
files/A_2.txt
s/A_3.txt #Error here
我认为这是一个与缓冲区相关的问题,但我不知道如何解决这个问题。 我的“其他程序”多次要求用户输入“Enter to continue”。但是,它被跳过了,因为我是从我的 shell 脚本中调用它的。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
我们今天的关于JS 条件添加到对象数组在 React 应用程序中给出了错误的结果和js添加对象到数组方法的分享就到这里,谢谢您的阅读,如果想了解更多关于angularjs – 如何在不使用require.js的情况下启动应用程序后,将模块添加到应用程序中?、delphi – TOSVersion给出了错误的结果、ember.js – Ember Inspector在检查我自己的ember应用程序时给出了错误、Grep 给出错误的结果的相关信息,可以在本站进行搜索。
本文标签: