有没有办法在使用RequireJS时设置templateSettingsfor lodash?
现在我在我的主要创业公司,
require(['lodash', 'question/view'], function(_, QuestionView) {
var questionView;
_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/g,
evaluate: /\{\%(.+?)\%\}/g
};
questionView = new QuestionView();
return questionView.render();
});
Run Code Online (Sandbox Code Playgroud)
但它似乎并不想设置templateSettings全局,因为当我_.template(...)在模块中使用时,它想要使用默认值templateSettings.问题是我不想在每个使用的模块中更改此设置_.template(...).
在一般意义上,我要解决的问题是将多级索引的一个组件更改为列.也就是说,我有一个Series包含多级索引的我想要将索引的最低级别更改为a中的列dataframe.这是我想要解决的实际示例问题,
在这里我们可以生成一些示例数据:
foo_choices = ["saul", "walter", "jessee"]
bar_choices = ["alpha", "beta", "foxtrot", "gamma", "hotel", "yankee"]
df = DataFrame([{"foo":random.choice(foo_choices),
"bar":random.choice(bar_choices)} for _ in range(20)])
df.head()
Run Code Online (Sandbox Code Playgroud)
这给了我们,
bar foo
0 beta jessee
1 gamma jessee
2 hotel saul
3 yankee walter
4 yankee jessee
...
Run Code Online (Sandbox Code Playgroud)
现在,我可以groupby bar并获得该foo字段的value_counts ,
dfgb = df.groupby('foo')
dfgb['bar'].value_counts()
Run Code Online (Sandbox Code Playgroud)
它输出,
foo
jessee hotel 4
gamma 2
yankee 1
saul foxtrot 3
hotel 2
gamma 1
alpha 1
walter hotel 2 …Run Code Online (Sandbox Code Playgroud) 我有List多个Section,每个部分都有不同类型的数据。对于每个部分,我想单击一个项目来呈现一个弹出窗口。
问题是,如果我将 附加.popover到Section或ForEach,那么.popover似乎会应用于列表中的每个条目。因此,即使只单击一个项目,也会为每个项目创建弹出窗口。
示例代码如下。我无法将 附加.popover到 ,List因为就我而言,有 2 种不同样式的.popover,并且每个视图只能附加一个.popover。
struct Item: Identifiable {
var id = UUID()
var title: String
}
var items: [Item] = [
Item(title: "Item 1"),
Item(title: "Item 2"),
Item(title: "Item 3"),
]
struct PopoverView: View {
@State var item: Item
var body: some View {
print("new PopoverView")
return Text("View for \(item.title)")
}
}
struct ContentView: View { …Run Code Online (Sandbox Code Playgroud)