列表中的选项可以在呈现后更改吗?(Can choices in a list be changed after it has been been rendered?)
我有一个w2ui表单,其中包含一个w2ui Drop List of options。 选择将根据用户选择用于调出表单的内容而有所不同。 我的问题是:Drop List的内容可以在呈现后更改吗?
使用标准的HTML控件,我会这样做:
$("#mySelect option[value='xyz']").remove();
要么
$("#mySelect").append('<option value="abc">abc</option>');
这些操作可以使用w2ui Drop List完成吗? 任何示例代码?
I have a w2ui form that contains a w2ui Drop List of choices. The choices will be different depending on what the user selected to bring up the form. My question is: can the contents of a Drop List be changed after it has been rendered?
With standard HTML controls, I would do something like this:
$("#mySelect option[value='xyz']").remove();
or
$("#mySelect").append('<option value="abc">abc</option>');
Can these kinds of operations be done with a w2ui Drop List? Any example code?
原文:https://stackoverflow.com/questions/42031539
最满意答案
这可以通过以下方式完成:
http://www.lenholgate.com/blog/2009/07/error-cannot-pass-a-gchandle-across-appdomains.html
总结解决方案:
诀窍是你需要使用一个委托,它知道它与之相关的AppDomain,然后通过将委托转换为函数指针来调用委托。 这有效地将非托管调用封送到正确的AppDomain中,然后再执行托管c
将解决方案应用于您的代码,它按预期编译和执行:
#include "stdafx.h" #include <Windows.h> #include <msclr/gcroot.h> using namespace System; using namespace System::Runtime::InteropServices; #pragma unmanaged class IService { public: virtual void Operate() = 0; }; DWORD __stdcall MyNativeThread(LPVOID arg) { IService* service = (IService*)arg; service->Operate(); return 0; } void StartNativeThread(IService* service) { CloseHandle(CreateThread(NULL, 0, &MyNativeThread, service, 0, NULL)); } #pragma managed typedef void (__stdcall ConnectFnc)(); public ref class ServiceManagedImpl { public: ServiceManagedImpl() { m_OperateDelegate = gcnew Delegate(this, &ServiceManagedImpl::Operate); } ConnectFnc *GetDelegateFunctionPointer() { return (ConnectFnc*)(Marshal::GetFunctionPointerForDelegate(m_OperateDelegate).ToPointer()); } public: void Operate() { System::Console::WriteLine("ServiceManagedImpl::Operate: Domain: {0}", System::AppDomain::CurrentDomain->Id); } private: delegate void Delegate(); Delegate ^m_OperateDelegate; }; class ServiceImpl : public IService { public: ServiceImpl(ServiceManagedImpl^ managedImpl) { m_managedImpl = new msclr::gcroot<ServiceManagedImpl^>(managedImpl); m_pFunction = (*m_managedImpl)->GetDelegateFunctionPointer(); } ~ServiceImpl() { delete m_managedImpl; } void operator()() const { m_pFunction(); } virtual void Operate() override { m_pFunction(); } private: msclr::gcroot<ServiceManagedImpl^> *m_managedImpl; ConnectFnc *m_pFunction; }; public ref class MyMmcSnapIn : MarshalByRefObject { public: MyMmcSnapIn() { System::Console::WriteLine("MyMmcSnapIn.ctor: Domain: {0}", AppDomain::CurrentDomain->Id); ServiceImpl testImpl = ServiceImpl(gcnew ServiceManagedImpl()); StartNativeThread(&testImpl); Threading::Thread::Sleep(10000); } }; int main() { Console::WriteLine(L"Main: Domain: {0}", AppDomain::CurrentDomain->Id); AppDomain^ mmcSnapInAppDomain = AppDomain::CreateDomain("AppDomainForMyMmcSnapIn"); // direct instantiation works as expected // gcnew MyMmcSnapIn(); String^ entryAssemblyLocation = Reflection::Assembly::GetEntryAssembly()->Location; mmcSnapInAppDomain->CreateInstanceFrom(entryAssemblyLocation, "MyMmcSnapIn"); return 0; }
This could be done the way is suggested here:
http://www.lenholgate.com/blog/2009/07/error-cannot-pass-a-gchandle-across-appdomains.html
To summarize the solution:
The trick is that you need to use a delegate, which knows about the AppDomain that it relates to, and then call through the delegate by converting it to a function pointer. This effectively marshals the unmanaged call into the correct AppDomain before executing the managed c
Applying the solution to your code, it compiles and executes as expected:
#include "stdafx.h" #include <Windows.h> #include <msclr/gcroot.h> using namespace System; using namespace System::Runtime::InteropServices; #pragma unmanaged class IService { public: virtual void Operate() = 0; }; DWORD __stdcall MyNativeThread(LPVOID arg) { IService* service = (IService*)arg; service->Operate(); return 0; } void StartNativeThread(IService* service) { CloseHandle(CreateThread(NULL, 0, &MyNativeThread, service, 0, NULL)); } #pragma managed typedef void (__stdcall ConnectFnc)(); public ref class ServiceManagedImpl { public: ServiceManagedImpl() { m_OperateDelegate = gcnew Delegate(this, &ServiceManagedImpl::Operate); } ConnectFnc *GetDelegateFunctionPointer() { return (ConnectFnc*)(Marshal::GetFunctionPointerForDelegate(m_OperateDelegate).ToPointer()); } public: void Operate() { System::Console::WriteLine("ServiceManagedImpl::Operate: Domain: {0}", System::AppDomain::CurrentDomain->Id); } private: delegate void Delegate(); Delegate ^m_OperateDelegate; }; class ServiceImpl : public IService { public: ServiceImpl(ServiceManagedImpl^ managedImpl) { m_managedImpl = new msclr::gcroot<ServiceManagedImpl^>(managedImpl); m_pFunction = (*m_managedImpl)->GetDelegateFunctionPointer(); } ~ServiceImpl() { delete m_managedImpl; } void operator()() const { m_pFunction(); } virtual void Operate() override { m_pFunction(); } private: msclr::gcroot<ServiceManagedImpl^> *m_managedImpl; ConnectFnc *m_pFunction; }; public ref class MyMmcSnapIn : MarshalByRefObject { public: MyMmcSnapIn() { System::Console::WriteLine("MyMmcSnapIn.ctor: Domain: {0}", AppDomain::CurrentDomain->Id); ServiceImpl testImpl = ServiceImpl(gcnew ServiceManagedImpl()); StartNativeThread(&testImpl); Threading::Thread::Sleep(10000); } }; int main() { Console::WriteLine(L"Main: Domain: {0}", AppDomain::CurrentDomain->Id); AppDomain^ mmcSnapInAppDomain = AppDomain::CreateDomain("AppDomainForMyMmcSnapIn"); // direct instantiation works as expected // gcnew MyMmcSnapIn(); String^ entryAssemblyLocation = Reflection::Assembly::GetEntryAssembly()->Location; mmcSnapInAppDomain->CreateInstanceFrom(entryAssemblyLocation, "MyMmcSnapIn"); return 0; }
相关问答
更多-
是的,.NET线程映射到当前所有CLR主机上的本机操作系统线程。 有一个选项可以通过ICLRTaskManager接口将它映射到托管API中的其他内容,如光纤,但实际上并未在任何主流主机中实现。 .NET 2.0时间框架中的SQL Server团队尝试了这一点,但是当他们无法使其足够可靠时,该项目就被放弃了。 这不是再次尝试。 从技术上讲,你可以运行一个自定义的托管CLR,由非托管程序启动,实现这种映射,但可能性很低。 Yes, a .NET Thread maps to a native operatin ...
-
可能最常见的是加载包含不受信任方的插件代码的程序集。 代码运行在自己的AppDomain中,隔离应用程序。 此外,不可能卸载特定程序集,但可以卸载AppDomains。 对于完整的破解,克里斯·布鲁姆(Chris Brumme)有一个巨大的博客条目: http://blogs.msdn.com/cbrumme/archive/2003/06/01/51466.aspx Probably the most common one is to load assemblies that contain plug-i ...
-
无法投射'SerializedMessage'类型的对象来键入'SerializedMessage'。 我将重点放在解决问题的核心问题上。 真正的消息应该是“类型Foo.SerializedMessage类型Bar.SerializedMessage”。 换句话说,这里涉及两种类型,来自不同的程序集。 .NET类型的标识不仅仅是类名,还包括完全限定的程序集名称。 程序集显示名称和程序集版本和文化。 一个DLL地狱反措施。 检查你的程序集是如何构建的,并验证SerializedMessage只在你的任何程序集 ...
-
QueuedTaskScheduler:如何处理AppDomain卸载?(QueuedTaskScheduler: How to deal with AppDomain unload?)[2023-12-04]
你尝试过这样的事情(未经测试)吗? var domain = Thread.GetDomain(); var unloading = false; domain.DomainUnload += (s, e) => { unloading = true; _blockingTaskQueue.CompleteAdding(); }; while (true) { try { // For each task queued to the scheduler, t ... -
AppDomain和线程(AppDomain and threading)[2022-06-14]
您无法在AppDomain之间直接共享类的实例。 为此,您应该从MarshalByRefObject派生类,并使用远程处理从其他AppDomain访问该实例。 You cannot share instances of classes directly between AppDomains. To do so, you should derive the class from MarshalByRefObject and use remoting to access the instance from th ... -
从WinRT组件访问从托管代码不断更新的值(Accessing value from WinRT component that is continously updated from managed code)[2023-05-24]
我已经花了很长时间来解决可能出错的问题,但是将代码添加到页面的Loaded事件处理程序解决了这个问题。 我不确定它的相关性,但是当我在问题中给出的代码片段在OnNavigatedTo方法中运行时,nativeCapture组件可能在其方法上具有自我空指针(this->)。 我希望这可以帮助人们,如果他们有类似的问题。 I have worked quite some time on what may be going wrong, but adding the code to Loaded event ha ... -
托管C ++可以很好地访问非托管内存。 您只需传入指针并在托管c ++中使用它。 现在,如果您希望将该数据传递到其他.NET语言,则需要将该数据复制到托管内存结构或使用C#中的不安全代码 Managed C++ can access the unmanaged memory just fine. You can just pass in the pointer and use it in managed c++. Now, if you want to then pass that data into ot ...
-
重新启动AppDomain时,前台线程没有阻止应用程序(Foreground thread not holding up application when I restart the AppDomain)[2023-06-19]
请注意语句“应用程序在其所有前台线程终止之前无法终止”中的“application”一词。 如果回收,申请不会终止。 在回收期间,ASP.NET正在卸载旧的AppDomain并加载新的AppDomain。 一切都在单一过程中完成。 流程未终止。 在AppDomain卸载范围内,所有线程(Background和Foreground)都被终止。 因此,ASP.NET不会在回收期间等待前台线程完成。 尝试使用简单的控制台应用程序,在其Main方法中创建Foreground线程。 它将一直有效,直到线程终止。 Pl ... -
如何强制从本机线程访问托管代码的正确AppDomain?(How do I force right AppDomain from native thread accessing managed code?)[2022-08-31]
这可以通过以下方式完成: http://www.lenholgate.com/blog/2009/07/error-cannot-pass-a-gchandle-across-appdomains.html 总结解决方案: 诀窍是你需要使用一个委托,它知道它与之相关的AppDomain,然后通过将委托转换为函数指针来调用委托。 这有效地将非托管调用封送到正确的AppDomain中,然后再执行托管c 将解决方案应用于您的代码,它按预期编译和执行: #include "stdafx.h" #include您可以在程序集触发的事件上自行解决其他DLL,以告知您无法找到类型。 AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += MyResolve; AppDomain.CurrentDomain.AssemblyResolve += MyResolve; private Assembly MyResolve(Object sender, ResolveEventArgs e) { Console.Error.WriteLine("Resol ...相关文章
更多- Python 列表(list)操作
- FreeMarker集合(List、Map)
- A Great List of Windows Tools
- 源码解读Mybatis List列表In查询实现的注意事项
- Map、List集合类的清空使用clear还是重新new呢
- Solr: a custom Search RequestHandler
- hibernate 对list修改
- List用完后需要赋null吗
- java List排序一
- redis整合spring示例二—java操作redis(存对象及List)
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)