如何使用具有实体数组的实体来实现此symfony表单?(how to implement this symfony form, with a entity which has a array of entities?)
我有一个symfony形式的大问题。 我需要做以下事情:
我想为实体生成一个表单,但是这个实体还有一个其他实体的数组,这些实体也应该被添加(如果可能的话)。
这里是数据结构:我有一个名为Foo的实体(保存一个FooItems数组)和一个实体FooItems。
class Foo { {...} /** * @var string * @ORM\Column(type="string") */ private $fooItems; {...}
现在我需要为此构建一个表单,用户可以向Foo添加一个或多个FooItem。 怎么实现这个?
i have a big problem with a symfony form. i need to do the following:
I want to generate a form for a entity, but this entity has a array of other entities which should be also added (if possible).
here is the data structure: I hava a Entity called Foo (keeps a array of FooItems) and the a entity FooItems.
class Foo { {...} /** * @var string * @ORM\Column(type="string") */ private $fooItems; {...}
now i need to build a form for this, the user can add one or more FooItems to the Foo. How to realise this?
原文:https://stackoverflow.com/questions/13900422
最满意答案
在这个例子中,这个用例已经有一些代码。
providers: [{provide: TEST_VALUE, useValue: 'Just an example'}],
你可以用它来注入字符串
Just an example
到LoginDialogComponent
。在你必须按照以下方式初始化
TEST_VALUE
之前:const TEST_VALUE = new OpaqueToken("test_value");
然后,您可以通过这种方式扩展组件构造函数以获取值:
constructor(@Inject(TEST_VALUE) private myValue: string) {}
要么
你也可以传递一个对象来代替字符串。 这看起来是这样的:
providers: [{provide: TEST_VALUE, useValue: <IMyDialogArgs>{ foo: "foo", bar: 0 }}],
In the example there is already some code for this use-case.
providers: [{provide: TEST_VALUE, useValue: 'Just an example'}],
You can use this to inject the string
Just an example
into the construtor ofLoginDialogComponent
.Before you have to initialize
TEST_VALUE
the following way:const TEST_VALUE = new OpaqueToken("test_value");
Then you can extend your components constructor this way to get the value:
constructor(@Inject(TEST_VALUE) private myValue: string) {}
Or
Instead of a string you can also pass an object. This would look this way:
providers: [{provide: TEST_VALUE, useValue: <IMyDialogArgs>{ foo: "foo", bar: 0 }}],
相关问答
更多-
这是目前报道的QtCreator错误: https://bugreports.qt-project.org/browse/QTCREATORBUG-10940?page=com.atlassian.streams.streams-jira-plugin:activity-stream-issue-tab https://bugreports.qt.io/browse /请见QTCREATORBUG-10940 所以不要担心警告,它会被修复 This is currently a reported QtCre ...
-
使用mdl自定义对话框时,如何传递组件的输入参数?(How do I pass input parameters for a component when using mdl custom dialog?)[2023-04-20]
你不能在你的情况下使用@Input,因为这需要一个你可以传递requireCaptcha值的元素。 目的是使用providers Array将值传递给对话框组件。 首先创建一个InjectionToken: export const REQUIERE_CAPTCHA = new InjectionToken('requireCaptcha'); 然后在你的showCustomDialog方法中使用: let pDialog = this.dialogService.showCustomD ... -
在碎片中使用DIalog(Working with DIalogs in Fragments)[2022-07-15]
首先,我可能会错过一些东西,没有代码等等,但... 其次:也许你不应该使用dialoges? 看起来像一个繁琐的用户界面。 只需使用这些片段呢? 虽然你说你正在使用DialogFragments,所以也许你已经考虑过了,并将它们用作“常规”片段。 第三:当显示的片段被移除/隐藏时关闭对话框? 例如,在片段或更集中的地方使用onStop()回调,您可能会保存当前显示的片段并决定显示一个新的片段。 通过调用对话框中的对象或片段或关闭活动中的对话框来关闭对话框。 请参阅解除对话: http : //develop ... -
在使用命令式对话框时,如何为组件提供参数?(How do I provide parameters for the component when working with imperative Dialogs?)[2023-11-17]
在这个例子中,这个用例已经有一些代码。 providers: [{provide: TEST_VALUE, useValue: 'Just an example'}], 你可以用它来注入字符串Just an example到LoginDialogComponent 。 在你必须按照以下方式初始化TEST_VALUE之前: const TEST_VALUE = new OpaqueToken("test_value"); 然后,您可以通过这种方式扩展组件构造函数以获取值: constructor(@Inje ... -
顺序显示多个对话框(Sequentially show multiple dialogs)[2022-12-30]
您可以选择使用累积对话框。 这只是一个普通的对话框,你可以在其中输入一个字符串: String info = "GPS: Connected\nWiFi: NOT Connected\n\nBattery: 45%"; (只是举个例子)。 这样,您可以使用\ n (新行)作为连接器将所有消息连接到一个字符串中(将其设置为双倍,以分隔不一致的信息 - 例如电池状态,在示例中)。 你会得到一个单一的信息面板 。 像(在例子中): GPS:已连接 WiFi:未连接 电池:45% You might opt fo ... -
Phonegap中的对话框?(Dialogs in Phonegap?)[2023-08-31]
使用 alert("on device ready!!!!"); 要么 navigator.notification.alert("PhoneGap is working"); Use alert("on device ready!!!!"); or navigator.notification.alert("PhoneGap is working"); -
您应该将IP地址作为Connect类构造函数的参数传递。 然后,您可以查看FactoryModuleBuilder,以便可以在代码中为Connect类注入依赖项。 至于你对单身人士的要求,我不太清楚你的意思。 根据定义,单例意味着只有一个类的实例。 在这里,你想要两个(或可能更多)。 我怀疑的是,在整个应用程序中,每个IP字符串最多只需要一个Connect实例。 如果是这种情况,您的工厂需要比FactoryModuleBuilder自动创建的工厂更聪明一些。 它可以是一个单例本身,并存储一个索引(map?c ...
-
离子 - 本地对话框(Ionic - native dialogs)[2024-02-03]
要在Ionic Framework应用程序中使用本机警报,您需要首先安装Cordova对话框插件: cordova plugin add cordova-plugin-dialogs 该插件默认不包含在Ionic Framework中。 安装插件后,您可以使用警报对话框: navigator.notification.alert( "Feil brukernavn eller passord.", // the message function() {}, ... -
JSON.stringify方法接受js对象并返回该对象的字符串化版本。 例如,如果将js对象{ name: 'shyju' }传递给此方法,您将获得字符串{"name":"shyju"} 当ajax调用是GET类型时,数据将作为查询字符串值发送。 $.ajax方法会根据需要将您在data属性中传递的js对象转换为querystring键值对并发送它。 所以基本上你当前的代码就像这样发送查询字符串 Home/SaveNewStagePlan?{"name":"shyju"}` 所以你可以清楚地看到这不是一 ...
-
在尝试使用div之前,你必须将div附加到某个东西上。 喜欢 document.append(''); You have to append that div to something before trying to use it. Like document.append('');