GVKun编程网logo

函数参数值在JS中的对象分解中不起作用(js函数参数为对象)

9

对于想了解函数参数值在JS中的对象分解中不起作用的读者,本文将提供新的信息,我们将详细介绍js函数参数为对象,并且为您提供关于$http.post在AngularJS中不起作用、.filter在jav

对于想了解函数参数值在JS中的对象分解中不起作用的读者,本文将提供新的信息,我们将详细介绍js函数参数为对象,并且为您提供关于$ http.post在AngularJS中不起作用、.filter在javascsript中的对象数组上不起作用、Ajax在JSF 2应用程序中不起作用、Android Emulator插件在Jenkins中不起作用的有价值信息。

本文目录一览:

函数参数值在JS中的对象分解中不起作用(js函数参数为对象)

函数参数值在JS中的对象分解中不起作用(js函数参数为对象)

从字面上看,该代码正在寻找一个名为propertyName的属性。要将propertyName中的值用作属性名称,您需要使用计算符号,并且需要指定将属性值放在何处。例如,将其放入现有的example变量中:

let extractProperty = (propertyName) => {
  ({ [propertyName]: example,...rest } = filters);
//   ^−−−−−−−−−−−−^^^^^^^^^^
  console.log(example);
};

extractProperty("brands");

您的代码是在假设rest已经存在的情况下编写的,但是我怀疑您真的想在本地声明它,以及用于接收属性值的变量:

let extractProperty = (propertyName) => {
  const { [propertyName]: example,...rest } = filters;
  console.log(example);
};

extractProperty("brands");

如果没有constlet(或var,但不推荐使用var),除非您在封闭范围内声明了rest,否则该代码将要么失败ReferenceError(在严格模式下),要么沦为我所谓的The Horror of Implicit Globals(宽松模式),自动创建一个全局变量。

,

为什么只想获得财产时在这里使用销毁?

let filters = {
  brands: { value:'b' },price: { value:'p' },sizes: { value:'s' },}

let extractProperty = propertyName =>
  console.log(filters[propertyName])

extractProperty("brands");

$ http.post在AngularJS中不起作用

$ http.post在AngularJS中不起作用

当我使用$http.get我的代码时,但是如果我使用$ http.post,则永远不会将参数获取到请求.php文件中。

这是服务功能:

    TestPanel.service(''MySampleService'', function ($http, $q) {    this.getAllPosts = function () {        var def = $q.defer();        $http.post(''/data/AJAXRequest.php'', ''mydata=1&abcd=2'').success(function (data) {            if (data == null)                def.reject(''ERROR: DATA IS NULL'');            else if (data.HasError)                def.reject(''ERROR: '' + data.Message);            else                def.resolve(data);        }).error(function () {            def.reject(''ERROR: Sorry, unable to complete your request.'');        });        return def.promise;    }});

和控制器功能:

 TestController.controller(''PostCtrl'', [''$scope'', ''$http'', ''MySampleService'',    function ($scope, $http, MySampleService) {        function FetchPostsList() {            MySampleService.getAllPosts().then(function (data) {                $scope.lstPosts = data.ResponseData;                $scope.totalRecords = data.totalRecords;                console.info(''DATA='' + $scope.lstPosts);            },            function (err) {                console.info(''err='' + err);            });        }        FetchPostsList();    }]);

和我的AJAXRequest.php文件

<?php    var_dump($_POST)?>

如果我使用 $ http.post()

输出

 array (size=0)  empty

如果我使用 $ http.get(), 我的输出是:

array (size=2)  ''mydata'' => string ''1'' (length=1)  ''abcd'' => string ''2'' (length=1)

我检查了FireBug工具中的帖子,该帖子将数据发送到我的php文件中。但PHP文件没有参数。

如果我使用 $ .ajax$ .post 我的代码工作,它会给出响应。

答案1

小编典典

如果您在标头中指定内容类型怎么办,特别是这样:

$http({method: ''POST'',url: ''/data/AJAXRequest.php'',data: { mydata: 1, abcd: 2 },headers: {''Content-Type'': ''application/x-www-form-urlencoded''}}).success(....);

找到了与PHP有关的注释,专门针对此问题:AngularJs $http.post()不发送数据
看来Angular默认以application / json的形式发送,这可能会使PHP感到困惑。

.filter在javascsript中的对象数组上不起作用

.filter在javascsript中的对象数组上不起作用

filter()不会修改变量本身。而是返回结果的新列表/数组。这是documentation。

这是您问题的解决方案:

const items = [{ productid:'a' },{ productid:'b' },{ productid:'c' }];

const theItem = { productid:'b' };

// assigning the value to a variable
const results = items.filter(item => item.productid === theItem.productid);

results.forEach(element => console.log(element));
Output: {productid: "b"}
,

Array.prototype.filter()返回一个新的过滤后的数组,它不会变异原始数组。您需要像这样修改代码:

方法-1: 将原始数组项更改为let而不是const,以便您可以将过滤器中的结果保存到项中,然后遍历项: //从const更改为let,这样我可以将过滤后的数组保存到该数组中

let items = [{productid:'a'},{productid:'b'},{productid:'c'}];
const theItem = {productid:'b'};

//Store the resultant array from filter into the original array 
items = items.filter( item => item.productid === theItem.productid);

items.forEach(element => console.log(element));

方法-2: 将过滤后的数组存储在新的数组中:

const items = [{productid:'a'},{productid:'c'}];
const theItem = {productid:'b'};

//Store the resultant array from filter into a new array 
const filteredItems = items.filter( item => item.productid === theItem.productid);

filteredItems.forEach(element => console.log(element));

Ajax在JSF 2应用程序中不起作用

Ajax在JSF 2应用程序中不起作用

尝试使用< f:ajax render =“@ form”listener =“#{myBean.onSelectItemChange}”/>刷新表单时出错.

弹出窗口中的消息是“emptyResponse:从服务器收到空响应.检查服务器错误日志.”

在Firefox控制台中,错误是“XML解析错误:XML或文本声明不在实体位置的开头”

相同的代码在我的本地环境中运行良好.我在本地和生产环境中都使用Tomcat 9.我只在生产中遇到错误.

xhtml页面以.开头

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

渲染时,<!DOCTYPE html>会自动添加到页面顶部.

我还尝试添加<?xml version =“1.0”encoding =“UTF-8”?>在页面顶部.

编辑:
更具体的错误:
XML解析错误:XML或文本声明不在实体的开头位置:http://serverIP:8080/app/myPage行号2,第1列:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>

更新:XHR响应如下所示:

<?xml version='1.0' encoding='UTF-8'?>
<?xml version='1.0' encoding='UTF-8'?>
<partial-response>
...
</partial-response>

第一行重复两次

顺便说一句,该应用程序在我的开发环境中正常工作.我在开发(Windows)和生产(Ubuntu)计算机上使用Tomcat9.

解决方法

如果客户端记录此错误,则服务器端XHTML不应该受到指责或仅是间接指责.了解browswer开发人员工具中真正的响应将显示真正的原因.

在你这样做后,很明显有一个“重复”的序言.在标题中(或在谷歌搜索中)使用它很可能会指向Stackoverflow中的现有Q / A并有效地使此Q / A与其重复:Ajax update has no effect,Firefox errors: XML or text declaration not at start of entity

我仍然将此作为答案发布有两个原因:

>向他人展示“根本原因分析”的相关性>由于它上面的赏金,它不能被标记为重复

Android Emulator插件在Jenkins中不起作用

Android Emulator插件在Jenkins中不起作用

当我在带有选项create emulator的Jenkins上运行测试时,出现以下问题:

[android]无法创建Android模拟器:无法运行AVD创建命令

当我以现有仿真器为目标时,会遇到以下问题:

致命:C:\ Windows \ system32 \ config \ systemprofile.android \ avd \
AVD_2.2.ini(系统找不到指定的路径)java.io.FileNotFoundException:C:\ Windows \ system32
\ config \ systemprofile.android \ avd \
AVD_2.2.ini(系统找不到指定的路径),位于java.io.FileInputStream.open(本机方法),位于java.io.FileInputStream。(未知源),位于java.io.FileReader。(未知源)在hudson.plugins.android_emulator.SdkInstaller
$
2.call(在hudson.plugins.android_emulator.util.Utils.parseConfigFile(Utils.java:436)在hudson.plugins.android_emulator.SdkInstaller
$
2.call(SdkInstaller.java:331)在.java:328),位于hudson.remoting.LocalChannel.call(LocalChannel.java:45),位于hudson.plugins.android_emulator.SdkInstaller.getPlatformFromExistingEmulator(SdkInstaller.java:328),位于hudson.plugins.android_emulator。位于hudson.plugins.android_emulator.SdkInstaller.installDependencies(SdkInstaller.java:174)的sdkInstaller.getPlatformForEmulator(SdkInstaller.java:312)位于hudson.plugins.android_emulator.AndroidEmulator.setUp(AndroidEmulator.java:247)处。在hudson.model.FreeStyleBuild上的$
BuildExecution.doRun(Build.java:154)在hudson.model.Run.execute(Run.java:1488)在hudson.model.FreeBuild。在hudson.model.Executor.run(Executor.java:236)处运行(FreeStyleBuild.java:46)在hudson.model.ResourceController.execute(ResourceController.java:88)hudson.model的model.Build
$
BuildExecution.doRun(Build.java:154)hudson.model的hudson.model.Run.execute(Run.java:1488)的AbstractBuild
$ AbstractBuildExecution.run(AbstractBuild.java:499)
hudson.model.ResourceController.execute(ResourceController.java:88)的.FreeStyleBuild.run(FreeStyleBuild.java:46)hudson.model.Executor.run(Executor.java:236)的。hudson.model的model.Build
$
BuildExecution.doRun(Build.java:154)hudson.model的hudson.model.Run.execute(Run.java:1488)的AbstractBuild
$ AbstractBuildExecution.run(AbstractBuild.java:499)
hudson.model.ResourceController.execute(ResourceController.java:88)的.FreeStyleBuild.run(FreeStyleBuild.java:46)hudson.model.Executor.run(Executor.java:236)的。

我有这个档案。当我在jenkins上运行手动模拟器并进行测试时,它可以工作。

关于函数参数值在JS中的对象分解中不起作用js函数参数为对象的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于$ http.post在AngularJS中不起作用、.filter在javascsript中的对象数组上不起作用、Ajax在JSF 2应用程序中不起作用、Android Emulator插件在Jenkins中不起作用等相关知识的信息别忘了在本站进行查找喔。

本文标签:

上一篇Msal.js 2.2 PKCE授权流程刷新令牌丢失(刷新令牌错误)

下一篇将ElephantSQL与node.js连接(node.js怎么连接数据库)