本文整理汇总了Python中pyquery.PyQuery.attr['data-riot-id']方法的典型用法代码示例。如果您正苦于以下问题:Python PyQuery.attr['data-riot-id']方法的具体用法?Python PyQuery.attr['data-riot-id']怎么用?Python PyQuery.attr['data-riot-id']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyquery.PyQuery
的用法示例。
在下文中一共展示了PyQuery.attr['data-riot-id']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_document
# 需要导入模块: from pyquery import PyQuery [as 别名]
# 或者: from pyquery.PyQuery import attr['data-riot-id'] [as 别名]
def render_document(vnode, expressions, context):
for expression in expressions:
evaluation = evaluate_expression(expression, context)
node = expression.get('node')
if isinstance(expression.get('value'), basestring) and expression.get('value') == evaluation:
continue
expression['value'] = evaluation
if expression.get('type') == 'each':
if expression.get('parent'):
parent = expression.get('parent')
else:
parent = node.parent()
expression['parent'] = parent
riot_id = node.attr['data-riot-id']
original_children = parent.children('[data-riot-id="%s"]' % riot_id)
# 0. add placeholder
placeholder = PyQuery('<text></text>')
placeholder.insertBefore(original_children.eq(0))
# 1. remove children
original_node = original_children.clone()
original_children.remove()
expression['node'] = original_node
# 2. insert children
loopcontext = {}
loopcontext.update(context if isinstance(context, dict) else vars(context))
expressions_col = []
for loop_index, item in enumerate(evaluation):
loopcontext.update(item if isinstance(item, dict) else vars(item))
loopcontext['loopindex'] = loop_index
child_node = PyQuery(expression.get('impl'))
child_node.attr['data-riot-loopindex'] = str(loop_index)
expressions = parse_document_expressions(child_node)
expressions_col.append((expressions, loopcontext))
render_document(vnode, expressions, loopcontext)
child_node.insertBefore(placeholder)
# 3. remove placeholder
if len(evaluation) == 0:
placeholder.attr['data-riot-id'] = str(riot_id)
else:
placeholder.remove()
mark_dirty(parent)
generate_widget(parent)
for expressions, loopcontext in expressions_col:
connect_signals(vnode, expressions, loopcontext)
continue
if expression.get('type') == 'markup':
node.attr['markup'] = json.dumps(evaluation)
node.html('')
mark_dirty(node)
continue
if expression.get('type') == 'attribute':
attribute = expression.get('attribute')
node.attr[attribute] = str(evaluation)
mark_dirty(node)
continue