小编Vit*_*Cpp的帖子

jQuery Validation插件不验证动态创建的表单元素

我有一个表单,您可以动态地添加带有输入元素的新行.在提交表单之前,可以使用http://jqueryvalidation.org/上的插件进行验证.目前,添加带输入元素的新行的代码如下所示:

function addTimeRow(table, stime)
{
    //var rowIdx = $('#seminarTimes tr').length - 1;

    var $id = $('<input type="hidden" name="stid[]">');
    var $dateField = $('<input type="text" name="date[]" class="input-mini">');
    var $date = $('<div class="input-append date">')
        .append($dateField)
        .append('<span class="add-on"><i class="icon-calendar">');
    var $from = $('<input type="text" name="from[]" class="input-mini"> <span>(hh:mm)</span>');
    var $to = $('<input type="text" name="to[]" class="input-mini"> <span>(hh:mm)</span>');

    if (typeof(stime) !== 'undefined')
    {
        $id.attr('value', stime.id);
        $dateField.attr('value', stime.date);
        $from.attr('value', stime.from);
        $to.attr('value', stime.to);
    }
    else
        $id.attr('value', -1);

    // Attach new input row.
    table
        .append($('<tr>')
            .append($id)
            .append($('<td>')
                .append($date)) …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-validate

12
推荐指数
2
解决办法
3万
查看次数

如何应用DOP并保持良好的用户界面?

目前我想为控制台优化我的3D引擎.更确切地说,我希望更多的缓存友好,并使我的结构更加面向数据,但也希望保持我不错的用户界面.

例如:

bool Init()
{
  // Create a node
  ISceneNode* pNode = GetSystem()->GetSceneManager()->AddNode("viewerNode");

  // Create a transform component
  ITransform* pTrans = m_pNode->CreateTransform("trans");
  pTrans->SetTranslation(0,1.0f,-4.0f);
  pTrans->SetRotation(0,0,0);

  // Create a camera component
  ICamera* pCam = m_pNode->CreateCamera("cam", pTrans);
  pCam->LookAt(Math::Vec3d(0,0,0));

  // And so on...
}
Run Code Online (Sandbox Code Playgroud)

因此用户可以在他的代码中使用接口指针.


在我的引擎中,我目前存储指向场景节点的指针.

boost::ptr_vector<SceneNode> m_nodes
Run Code Online (Sandbox Code Playgroud)

因此,在面向数据的设计中,最好使用数组结构而不是结构数组.所以我的节点来自......

class SceneNode
{
private:
  Math::Vec3d m_pos;
};

std::vector<SceneNode> m_nodes;
Run Code Online (Sandbox Code Playgroud)

对...

class SceneNodes
{
  std::vector<std::string> m_names;
  std::vector<Math::Vec3d> m_positions;
  // and so on...
};
Run Code Online (Sandbox Code Playgroud)

所以如果我想申请DOP,我会在这里看到两个问题.首先,如何在不让用户使用ID,索引等的情况下保持良好的用户界面?

其次,当一些向量调整大小而不让用户界面指针指向必杀技时,如何处理属性的重定位?

目前我的想法是实现一种handle_vector,你可以从中获得持久性"指针"的句柄:

typedef handle<ISceneNodeData> SceneNodeHandle;
SceneNodeHandle nodeHandle = nodeHandleVector.get_handle(idx);
Run Code Online (Sandbox Code Playgroud)

因此,当实习生std :: …

c++ caching vector relocation data-oriented-design

7
推荐指数
1
解决办法
2407
查看次数

如何为模板方法实现编译时 foreach() ?

我想实现一个编译时 foreach() ,它可以调用给定的模板成员函数 N 次。目前我有我的 foreach 编译时:

struct ForEach
{
   template <size_t Dummy>
   struct IntToType {};

   typedef IntToType<true> ForEachDoNotTerminateLoop;
   typedef IntToType<false> ForEachTerminateLoop;

   template <size_t TIdx, size_t TCount, typename TMethod>
   static void ForEachImpl(ForEachDoNotTerminateLoop, TMethod method)
   {
      method.Invoke<TIdx>();
      ForEachImpl<TIdx + 1, TCount, TMethod>(Internal::IntToType<(TIdx + 1 < TCount)>(), method);
   }

   template <size_t TIdx, size_t TCount, typename TMethod>
   static void ForEachImpl(ForEachTerminateLoop, TMethod method)
   {
   }

   template <size_t TCount, typename TMethod>
   static void Member(TMethod method)
   {
      ForEachImpl<0, TCount, TMethod>(Internal::IntToType<(0 < TCount)>(), method);
   }
};
Run Code Online (Sandbox Code Playgroud)

还有一些模板类: …

c++ templates template-meta-programming

5
推荐指数
1
解决办法
2984
查看次数