Angularjs:将对象传递给状态(Angularjs: passing an object params to state)
我想将一个物体传递给一个州。 我是这样做的:
.state('options', { url: "/options?current_task", views: { "middle": { templateUrl: "/games/options.html" } }
以下是我称之为:
$state.go("options", {current_task: task});
但是它没有传递一个对象,而是传递了一个String“Object Object”我做错了什么?
I'd like to pass an object to a state. Here is how I did it:
.state('options', { url: "/options?current_task", views: { "middle": { templateUrl: "/games/options.html" } }
And here is how I call it:
$state.go("options", {current_task: task});
But instead of passing an object, it passed a String "Object Object" What did I do wrong?
原文:https://stackoverflow.com/questions/20635430
更新时间:2022-05-13 14:05
最满意答案
你写:
sample ar[4]; ar[4] = { (1,2), (3,4), (5,6), (7,8) };
数组初始化程序的语法(仅在
ar
的初始化期间有效)是:sample ar[4] = { {1,2}, {3,4}, {5,6}, {7,8} };
C11(n1570),§6.7.9初始化
initializer: assignment-expression { initializer-list } { initializer-list , }
此外, 缩写对于编写可读代码很重要。
You have written:
sample ar[4]; ar[4] = { (1,2), (3,4), (5,6), (7,8) };
The syntax of the array initializer (only valid during the initialization of
ar
) is:sample ar[4] = { {1,2}, {3,4}, {5,6}, {7,8} };
C11 (n1570), § 6.7.9 Initialization
initializer: assignment-expression { initializer-list } { initializer-list , }
Also, indentation is important to write readable code.
相关问答
更多-
分配给结构数组(Assignment to the array of Structures)[2021-09-24]
你写: sample ar[4]; ar[4] = { (1,2), (3,4), (5,6), (7,8) }; 数组初始化程序的语法(仅在ar的初始化期间有效)是: sample ar[4] = { {1,2}, {3,4}, {5,6}, {7,8} }; C11(n1570),§6.7.9初始化 initializer: assignment-expression { initializer-list ... -
C中的结构数组(Structures array in C)[2022-09-23]
首先,由于已经从STRUCT.h完成,所以没有必要保护包含main的包含 所以,而不是在主 #ifndef STRUCT_H #include "struct.h" #endif 直接使用(在主要的.h是应该有它已经做了保护的那个,不需要做两次) #include "struct.h" 现在回到你的代码,你遇到的问题是你没有修改函数中的结构,这意味着rows [0] .posX = 1; 将永远不会执行 这应该工作: #include "struct.h" int main(void) { ... -
查看对结构元素的访问: typedef struct t_element { char eleID; int size; int color; }Element; typedef struct t_Menu { char IDmenu; char elementNumber; Element elements[100]; }Menus; int main() { Menus menus[20]; Element element1; ...
-
与所有“最有效率”的问题一样,唯一的方法就是在实际情况下测量实际表现。 一般来说,从连续内存位置的项目中可以获得很大的性能提升,因为对于任何一个接一个地处理项目的算法,这几乎总是最容易缓存的布局。 总体而言,连续数组使用更少的空间,因为您不需要额外的空间来存储额外的数据(如树节点)。 虽然在需要增长时将尺寸加倍是一种常见方法,但它可能会占用地址空间。 一些STL实现将结构像向量一样增长1.5倍,而不是2倍,以避免某些病态情况。 在短期内,这会导致更多的分配,但会导致更少的内存碎片。 如果你使用realloc ...
-
首先,使用正确的强制转换,因为你似乎知道如何指向一个数组: struct pdirectory (*test)[N] = (struct pdirectory (*)[N])0x00001000; 其次, test[i]将以数组大小为单位执行指针运算。 如果数组的大小为N ,那么数组访问将等同于: *(struct pdirectory(*)[N])((unsigned char*)test + i * sizeof(struct pdirectory) * N) 正如你所看到的,上面并没有给test指 ...
-
传递结构数组(Passing an Array of Structures)[2022-10-29]
当你返回它时你不应该取消引用数组1 ,它实际上是与函数返回类型不兼容的类型,只是 return array; 另外,在读取值之前检查array != NULL malloc()之后的array != NULL ,并且你真的不需要typedef它会让你的代码有点混乱。 如果您编译的代码我怀疑,那么您的编译器命令中没有启用警告,启用它们以便您可以防止出现此类问题。 (1) *array相当于array[0] 。 You should not dereference the array when you ret ... -
比较不同的数组结构(Compare different arrays structures)[2022-07-24]
如果将来的答案不正确,需要更改,我将隐藏在可用格式中的数组。 $desired = array(); $desired['info'][0]['player'] = 'Messi'; $desired['info'][0]['week']['id'] = 252; $desired['info'][0]['week']['videos'][2]['id'] = 2929847; $desired['info'][0]['week']['videos'][2]['link'] = 'dribbling ... -
结构数组(Array of structures)[2022-04-14]
改成: state states[] = { {'A', states+3, states+4}, //You probably meant states, since state is a type {'B', states, states+5}, {'C', states+4, states }, {'D', states+5, states+6}, {'E', states+1, states+7}, {'F', s ... -
从C#调用FORTRAN dll并将值分配给结构数组(Calling FORTRAN dll from C# and assigning values to array of structures)[2023-06-04]
我过去使用指针而不是数组做过这个。 我认为您的结构正在被复制用于P / Invoke调用: [DllImport("mathlib.dll")] static extern void TEST_REF(ValueRef* t, int n); 在调用方法之前,您需要固定数组。 fixed (ValueRef* pointer = t) { TEST_REF(pointer, n); } 编辑:根据注释,解决方案是将外部声明为 [DllImport("mathlib.dll")] static ext ... -
你需要a适当的结构数组,即用兼容的字段集初始化它: a = struct('ID', {}, 'pass', {}); b = struct('ID', 1, 'pass', 34); a(1) = b; You need a to be a proper structure array, i.e. initialise it with the compatible set of fields: a = struct('ID', {}, 'pass', {}); b = struct('ID', 1, ' ...