读取JavaScript对象中的对象属性值(Reading object property value in JavaScript object)

我正在尝试读取以下JavaScript对象的username属性并将其存储在变量中。

[ RowDataPacket { username: 'admin', password: 'admin' } ]

它作为结果对象从SQL查询返回给用户数据库。 返回的对象称为result然而,当我尝试访问它的属性

var sqlusername = result.username

要么

var sqlusername = result.RowDataPacket.username

要么

var sqlusername = result["username"]

或任何其他方式访问该财产,

变量var的值总是未定义的。

如何使用对象的用户名和密码属性?


I am trying to read the username property of the following JavaScript object and store it inside a variable.

[ RowDataPacket { username: 'admin', password: 'admin' } ]

It is being returned as a result object from an SQL query to a user database. The returned object is called result However, when I try to access its properties with

var sqlusername = result.username

or

var sqlusername = result.RowDataPacket.username

or

var sqlusername = result["username"]

or any other way to access the property,

the value of the variable var is always undefined.

How do I use the username and password properties of the object?


原文:https://stackoverflow.com/questions/49566257
2023-05-20 10:05

满意答案

摆脱那个网格组件。 你不需要这么简单的事情。 这是复杂的事情,因为它不是一个常规/常见的组件,我们不知道它是如何影响事物的。

这看起来很简单:

<View>
    <View style={{}}>
        <Image />
    </View>

    <View style={{flexDirection:'row'}}>
        <View>
            <Text>row 1, col 1</Text>
        </View>
        <View>
            <Text>row 1, col2Text>
        </View>
    </View>

    <View style={{flexDirection:'row'}}>
        <View>
            <Text>row 2, col 1</Text>
        </View>
        <View>
            <Text>row 2, col2Text>
        </View>
    </View>

    <View style={{}}>
        <Button title="Login" />
    </View>

</View>

这里有另外一个类似的问题 - 如何在没有第三方库的情况下创建3x3网格菜单?


Get rid of that grid component. You don't need it for such a simple thing. It's complicating things, and as it's not a regular/common component we don't know how it's affecting things.

This looks quite simple:

<View>
    <View style={{}}>
        <Image />
    </View>

    <View style={{flexDirection:'row'}}>
        <View>
            <Text>row 1, col 1</Text>
        </View>
        <View>
            <Text>row 1, col2Text>
        </View>
    </View>

    <View style={{flexDirection:'row'}}>
        <View>
            <Text>row 2, col 1</Text>
        </View>
        <View>
            <Text>row 2, col2Text>
        </View>
    </View>

    <View style={{}}>
        <Button title="Login" />
    </View>

</View>

Here's another similar question - How to create 3x3 grid menu in react native without 3rd party lib?

相关问答

更多

如何动态调整标题的徽标?(how can resize dynamically the logo of the header?)

由于浏览器的分辨率/大小取决于客户端,因此您可以在客户端解决此问题。 我建议查看JavaScript,因为它有这些方便的功能(以及更多): // Get the page width windowWidth = document.body.offsetWidth; // Get the page height windowHeight = document.body.offsetHeight; Since the resolution/size of the browser depends o...

徽标浮在标题上方或上方(Logo floating over or above header)

在您的徽标的CSS上,您已经申报了两次保证金。 您的上一个保证金设置将覆盖您的第一个保证金设置。 不确定你的意思是它在你的中心面板下消失了。 我在jsfiddle上重新创建了代码,使用了通用的150 x 100徽标图片,而您的代码只使用了第一个margin:0 50%; 。 这是一个链接http://jsfiddle.net/jaketaylor/1ut4ts76/让我知道你想要它看起来像什么,而不是它是如何出现的 On the CSS for your logo you have declare...

如何在顶部使用徽标标题来制作此网格?(How to make this grid with logo header at the top?)

摆脱那个网格组件。 你不需要这么简单的事情。 这是复杂的事情,因为它不是一个常规/常见的组件,我们不知道它是如何影响事物的。 这看起来很简单: <View> <View style={{}}> <Image /> </View> <View style={{flexDirection:'row'}}> <View> <Text>row 1, col 1</Text> </View> <...

Sticky Header Logo Hover [关闭](Sticky Header Logo Hover [closed])

这只是一个荒谬的实现,但我想你可能会得到这个想法。 $(window).scroll(function() { var $container = $(".container"); var container_offset = $container.offset().top - $(window).scrollTop(); console.log(container_offset); if(container_offset){ $container.addCla...

徽标没有显示在标题img的顶部(Logo not showing on top of header img)

以前的CSS代码: #header #logo { background:url(../Images/logo.png) no-repeat; width:272px; heigh:142px; cursor:pointer; } 建议修复 #header #logo { background:url(../Images/logo.png) no-repeat; width:272px; height:142px; cursor:pointer; } 让我分享一...

在标题中的同一行上创建徽标和链接(Make the logo and links on the same line in header)

它缺少CSS中id名称的# 。 事实上,整个布局可以使用简单的float来完成,因此在HTML中的横幅之前移动链接。 #header { background-color:#AC222A; color:white; } #links { float:right; } <div id="header"> <div id="links"> <a href="">home</a> &nbsp;|&nbsp; <a href="About.h...

在标题中添加徽标和其他图像(Adding Logo and other image in header)

另见: - http://jsfiddle.net/9wa8j/1/ 你说你想要像图像和文本相邻的东西。 对? 所以,根据我的理解,我尝试过这样的事情: - .s{ display:inline-block; } 查看此链接: - http://jsfiddle.net/9wa8j/ See this also:- http://jsfiddle.net/9wa8j/1/ You said you want something like image and the text adjacen...

在标题顶部移动div(Moving div on top of header)

我有一个更稳定/可移植的解决方案 - 只需在DOM中移动过滤器输入框: 将此添加到初始化: .. $('.dataTables_filter input').attr("placeholder", "enter seach terms here"); $('.dataTables_filter').css('float','none'); $('.dataTables_filter').css('padding-right','0px'); $("#example_filter")...

如何在Wordpress中使用CSS修复标题高度和调整徽标大小(How to fix header height and resize logo with CSS in Wordpress)

我添加了style =“position:absolute; height:100%;” 到一个img标签,它得到修复。 I added style="position:absolute; height:100%;" to an img tag and it got fixed.

对齐标题和徽标(Align Header and logo)

一种解决方案是使用vertical-align: middle来img like: body { font-family: sans-serif, Arial; font-size: 12px; color: #000000; margin: 0px; background-color: #d9d7d7; } h1, h2, h3, h4, h5, h6, p, ul, ol, li, form, input, textarea { ...

相关文章

更多

Object Oriented Programming

Some might also contend that inheritance should be ...

Cannot expose request attribute 'website' because of an existing model object of the same name 的解决方案

在使用springmvc+freemarker,有可能你会遇到以下异常(如:资源找不到重定向到404的 ...

Guava学习笔记:复写的Object常用方法

  在Java中Object类是所有类的父类,其中有几个需要override的方法比如equals,h ...

javascript 问题

&lt;s:iterator value=&quot;list_latest_course&quot; ...

从 prototype.js 深入学习 javascript 的面向对象特性

从 prototype.js 深入学习 javascript 的面向对象特性,js是一门很强大的语言, ...

javascript 对象转换成json格式数据(使用JSON.stringify)

方法一:new Object(),方法二:使用{}。然后使用JSON.stringify转为json格 ...

javascript快速入门

本节内容包括:js使用,变量简介,变量的作用域,变量的类型

javascript常用对象

本节的主要内容是javascript常用对象,包括Date对象、String对象和Array对象

javascript函数与对象

对应js而言没有类的概念,只有对象的概念,对象创建基本认识:使用函数就可以创建对象。定义函数直接用fu ...

孔浩javascript设计模式视频教程

js的Function和Object的深入理解,js的函数和对象的prototype,js的上下文,j ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本