2017-01-28 54 views

回答

1

你可以使用createViewModelmobx-utils

class Todo { 
    @observable title = "Test"; 
} 

const model = new Todo(); 
const viewModel = createViewModel(model); 

viewModel.title = "Get tea"; 
console.log(viewModel.isDirty); // true 

對於完整的MobX表單解決方案,您可以查看mobx-react-form,該支持在字段上檢查isDirty

+0

Tholle,你有這個createViewModel在areact組件中使用的例子 – Kamaraju

+0

@Kamaraju我沒有React的例子,很遺憾。也許你可以從[**文檔**](https://github.com/mobxjs/mobx-utils#createviewmodel)獲得一些啓發? – Tholle

+0

它沒有太多的細節如何使用它,謝謝 – Kamaraju